ryanmetzler3 Posted August 18, 2013 Share Posted August 18, 2013 Here is my html form and my php code. It is supposed to check if any of the forms have not been filled and echo a message if they have not. Then process the registration if they have. But it seems to ignore the blank spots. If I don't fill in fields it just processes the blank registration anyways. Where did I go wrong? <?php include ('config.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string(md5($_POST['password'])); $firstname = mysql_real_escape_string($_POST['firstname']); $lastname = mysql_real_escape_string($_POST['lastname']); $email = mysql_real_escape_string($_POST['email']); if (!isset($username) || !isset($password) || !isset($firstname) || !isset($lastname) || !isset($email) ) { echo "You did not fill out the required fields."; } else { $query = mysql_query("SELECT * FROM users WHERE username = '$username'"); $rows = mysql_num_rows($query); if ($rows > 0) { die("Username taken!"); } else { $user_input = mysql_query("INSERT INTO users (username, password, firstname, lastname, email) VALUES ('$username','$password','$firstname','$lastname','$email')"); echo("Succesfuly Registered!"); } } } ?> <html> <head> <title>Register</title> </head> <body> <form action="register.php" method="post"> First Name: <input type="text" name="firstname"><br/> Last Name: <input type="text" name="lastname" /><br/> Email: <input type="text" name="email" /><br/> Username: <input type="text" name="username" /><br/> Password: <input type="password" name="password"/><br/> <input type="submit" value="Register!"/> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
0xMatt Posted August 18, 2013 Share Posted August 18, 2013 What you're doing to process the form is only checking if those specific variable names are set which you have done. $username = mysql_real_escape_string($_POST['username']); So your code checks to see if $username is set, which you have just done above, even if the $_POST data for username is empty, $username is an empty string. So instead of using isset(), you'll want to replace all that with empty() in your argument. e.g if(empty($username)) { echo 'Username Empty'; } Quote Link to comment Share on other sites More sharing options...
kashiflatif90 Posted August 19, 2013 Share Posted August 19, 2013 try this..... doRegistration is the function on submit button function doRegistration() { if(first_name==""&&last_name==""&&user_name==""&&e_mail==""&&pass_word1==""&&pass_word2=="") { alert("Please Complete The Form Before Submission") return false; } else { return true; } Quote Link to comment Share on other sites More sharing options...
Solution gristoi Posted August 19, 2013 Solution Share Posted August 19, 2013 try this..... doRegistration is the function on submit button function doRegistration() { if(first_name==""&&last_name==""&&user_name==""&&e_mail==""&&pass_word1==""&&pass_word2=="") { alert("Please Complete The Form Before Submission") return false; } else { return true; } I am afraid kashiflatif90 is incorrect. that if statement will only ever be true if ALL fields are empty on submission . you should use || instead of && Quote Link to comment Share on other sites More sharing options...
kashiflatif90 Posted August 19, 2013 Share Posted August 19, 2013 I am afraid kashiflatif90 is incorrect. that if statement will only ever be true if ALL fields are empty on submission . you should use || instead of && thanks @gristoi for finding error... , also you should help me on finding Card Integration Code Quote Link to comment 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.