princeofpersia Posted March 28, 2011 Share Posted March 28, 2011 Hi guys, I have this registration form, for some reasons it just gives me "please all fields" on registration, can u help me see where im wrong please? thanks in advance code is attached below: <?php //php form registration starts here if(isset($_POST['register'])){ $title=strip_tags($_POST ['title']); $firstname=strip_tags($_POST['firstname']); $surname=strip_tags($_POST['surname']); $email=strip_tags($_POST ['email']); $reemail=strip_tags($_POST ['reemail']); $password=strip_tags($_POST ['password']); $repassword=strip_tags($_POST ['repassword']); $street=strip_tags($_POST ['street']); $city=strip_tags($_POST ['city']); $postcode=strip_tags($_POST ['postocde']); $telephone=strip_tags($_POST ['telephone']); if($title && $firstname && $surname && $email && $reemail && $password && $repassword && $street && $city && $postcode && $telephone) { $getemails=mysql_query("SELECT * FROM member WHERE email='$email'"); $row=mysql_fetch_assoc($getemails); if(mysql_num_rows($getemails) > 0) { echo "This email is already registered in our database"; } else { if($email!=$reemail) echo "Your Emails do not match"; } if($password!=$repassword) { echo "Passwords do not match"; } else { $confirmedpass=md5($password); $submitusers= mysql_query("INSERT INTO members (title,Firstname,Surname,Street,City,Postcode,EmailAddress,Password, TelephoneNo,Credit) VALUES ('$title','$firstname','$surname','$street','$city','$postcode','$email','$confirmedpass','$telephone','0')"); } } else {echo "Please fill All required fields";} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231952-registration-help-please/ Share on other sites More sharing options...
princeofpersia Posted March 28, 2011 Author Share Posted March 28, 2011 Just an update I have even changed the code but still get the same thing, if ($_POST['register']){ $title=strip_tags($_POST['title']); $firstname=strip_tags($_POST['firstname']); $surname=strip_tags($_POST['surname']); $email=strip_tags($_POST['email']); $reemail=strip_tags($_POST['reemail']); $password=strip_tags($_POST['password']); $repassword=strip_tags($_POST['repassword']); $street=strip_tags($_POST['street']); $city=strip_tags($_POST['city']); $postcode=strip_tags($_POST['postocde']); $telephone=strip_tags($_POST['telephone']); if($firstname == "" || $surname == "" || $email == "" || $reemail == "" || $password == "" || $repassword == "" || $street == "" || $city == "" || $postcode == "" || $telephone == "") echo "Please fill All required fields"; else { $getemails=mysql_query("SELECT * FROM member WHERE email='$email'"); $row=mysql_fetch_assoc($getemails); if(mysql_num_rows($getemails) > 0){ echo "This email is already registered in our database"; } else { if($email!=$reemail) echo "Your Emails do not match"; } if($password!=$repassword) { echo "Passwords do not match"; } else { $confirmedpass=md5($password); $submitusers= mysql_query("INSERT INTO members (title,Firstname,Surname,Street,City,Postcode,EmailAddress,Password, TelephoneNo,Credit) VALUES ('$title','$firstname','$surname','$street','$city','$postcode','$email','$confirmedpass','$telephone','0')"); } } } ?> and this is my html, checked everyhting and still get the error <!--Registration Form starts Here */ --> <form name="register" action="" method="POST"> <p><label for="title">Title</label> <select name="title"> <option value="Mr">Mr</option> <option value="Miss">Miss</option> <option value="Mrs">Mrs</option> <option value="Others">Others</option> </select></p> <p><label for="firstname">First Name:</label><br /><input type="text" name="firstname"/></p> <p><label for="surname">Surname:</label><br /><input type="text" name="surname" /></p> <p><label for="email">Email:<label><br /><input type="text" name="email" /></p> <p><label for="reemail">Repeat Email:<label><br /><input type="text" name="reemail" /></p> <p><label for="password">Password:<label><br /><input type="password" name="password" /></p> <p><label for="repassword">Repeat Password:<label><br /><input type="password" name="repassword" /></p> <p><label for="street">Street:</label><br /><input type="text" name="street" /></p> <p><label for="city">City:</label><br /><input type="text" name="city" /></p> <p><label for="postcode">Postcode:</label><br /><input type="text" name="postcode" /></p> <p><label for="telephone">Telephone No:</label><br /><input type="text" name="telephone" /></p> <p><input type="submit" name="register" value="Register" /></p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/231952-registration-help-please/#findComment-1193254 Share on other sites More sharing options...
Psycho Posted March 28, 2011 Share Posted March 28, 2011 If you added some better error handling to your code (e.g. being able to tell the user "what" fields were empty) it would have been easy to find this error yourself $postcode=strip_tags($_POST['postocde']); Note the name of the POST value. Quote Link to comment https://forums.phpfreaks.com/topic/231952-registration-help-please/#findComment-1193267 Share on other sites More sharing options...
princeofpersia Posted March 28, 2011 Author Share Posted March 28, 2011 thanks for your help, Its working now Quote Link to comment https://forums.phpfreaks.com/topic/231952-registration-help-please/#findComment-1193268 Share on other sites More sharing options...
Psycho Posted March 28, 2011 Share Posted March 28, 2011 Here is a rewrite of your code which fixes some other problems and adds better error handling. Let me know if you have any questions <?php //Parse user input $title = trim(strip_tags($_POST['title'])); $firstname = trim(strip_tags($_POST['firstname'])); $surname = trim(strip_tags($_POST['surname'])); $email = trim(strip_tags($_POST['email'])); $reemail = trim(strip_tags($_POST['reemail'])); $password = $_POST['password']; //Don't need to trim or remove tags $repassword = $_POST['repassword']; $street = trim(strip_tags($_POST['street'])); $city = trim(strip_tags($_POST['city'])); $postcode = trim(strip_tags($_POST['postocde'])); $telephone = trim(strip_tags($_POST['telephone'])); //Check for errors $errors = array(); if(empty($firstname)) { $errors[] = "First name is required."; } if(empty($surname)) { $errors[] = "Surname is required."; } if(empty($email)) { $errors[] = "Email is required."; } if(empty($reemail)) { $errors[] = "Email confirmation is required."; } if(!empty($email) && !empty($reemail)) { if($email!=$reemail) { $errors[] = "Your Emails do not match."; } else { $emailSQL = mysql_real_escape_string($email); $result = mysql_query("SELECT * FROM member WHERE email='$emailSQL'"); if(mysql_num_rows($result)) { $errors[] = "This email is already registered in our database"; } } } if(empty($password)) { $errors[] = "Password is required."; } if(empty($repassword)) { $errors[] = "Password confirmation is required."; } if(!empty($password) && !empty($repassword) && $password!=$repassword) { $errors[] = "Your Passwords do not match."; } if(empty($street)) { $errors[] = "Street is required."; } if(empty($city)) { $errors[] = "City is required."; } if(empty($postcode)) { $errors[] = "Post code is required."; } if(empty($telephone)) { $errors[] = "Telephone is required."; } //Determine if errors occured if(count($errors)>0) { //There were errors - display them echo "The following errors occured:<br />\n"; echo "<ul>\n"; foreach($errors as $error) { echo "<li>{$error}</li>\n"; } echo "</ul>\n"; } else { //No errors occured - insert records $query = sprint_f("INSERT INTO members (title, Firstname, Surname, Street ,City, Postcode, EmailAddress, Password, TelephoneNo, Credit) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%d')", mysql_real_escape_string($title), mysql_real_escape_string($firstname), mysql_real_escape_string($surname), mysql_real_escape_string($street), mysql_real_escape_string($city), mysql_real_escape_string($postcode), $emailSQL, md5($password), mysql_real_escape_string($telephone), 0); $submitusers= mysql_query($query); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231952-registration-help-please/#findComment-1193283 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.