xgd Posted July 4, 2009 Share Posted July 4, 2009 Hello people, I've made this registration script that actually works, nut i get weird problems when i try to submit it with emty fields or when i try to use 2 different passwords while registering. If i try to submit it without entering anything into the fields, i get the following error message: Didnt fill in FIRST NAME Didnt fill in LAST NAME Didnt enter EMAIL Didnt enter pass Notice: Undefined variable: fn in C:\Program Files\EasyPHP 3.0\www\register.php on line 76 And if i try to submit it using 2 different passwords i get this: Passwords dont match Notice: Undefined variable: p in C:\Program Files\EasyPHP 3.0\www\register.php on line 76 so the script actually works, it registers normally if everything is OK, and it doesnt register if something is not valid, but i get these weird error messages of undefined variables that i believe i have defined. the script goes like this: <?php // SET UP THE DATA INPUT FIELDS if (isset($_POST['submit'])) { require_once('db_connect.php'); if (empty($_POST['first_name'])) { echo "Didnt fill in FIRST NAME<br />"; } else { $fn = trim($_POST['first_name']); } if (empty($_POST['last_name'])) { echo "Didnt fill in LAST NAME<br />"; } else { $ln = trim($_POST['last_name']); } if (empty($_POST['email'])) { echo "Didnt enter EMAIL<br />"; } else { $e = trim($_POST['email']); } if (!empty($_POST['pass1'])) { if ($_POST['pass1'] != $_POST['pass2']) { echo "Passwords dont match<br />"; } else { $p = trim($_POST['pass1']); } } else { echo "Didnt enter pass<br />"; } if ($fn && $ln && $e && $p) { // MAKE SURE EMAIL ADDRESS IS NOT ALREADY IN USE $q = "SELECT user_id FROM users WHERE email='$e'"; $r = mysqli_query($dbc, $q) or trigger_error("Problem with query".mysqli_error($dbc)); if (mysqli_num_rows($r) == 0) { $q = "INSERT INTO users (email, pass, first_name, last_name, reg_date) VALUES ('$e', SHA1('$p'), '$fn', '$ln', NOW() )"; $r = mysqli_query($dbc, $q) or trigger_error("error inserting".mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { echo "you have been regiatered"; } else { echo "System error, you could not be registered"; } } else { echo "Email address already in use, choose another one"; } } } ?> What is wrong with this WORKING code ? ??? Quote Link to comment https://forums.phpfreaks.com/topic/164756-weird-script-problems-please-help/ Share on other sites More sharing options...
.josh Posted July 4, 2009 Share Posted July 4, 2009 empty() assumes that the variables are defined, but empty. So if you don't enter anything in the form for them and they don't exist, you get the error because they are undefined. Try using isset instead of empty() Quote Link to comment https://forums.phpfreaks.com/topic/164756-weird-script-problems-please-help/#findComment-868770 Share on other sites More sharing options...
xgd Posted July 4, 2009 Author Share Posted July 4, 2009 Hey man, just tried it, it is still the same. Any other suggestions ? Quote Link to comment https://forums.phpfreaks.com/topic/164756-weird-script-problems-please-help/#findComment-868826 Share on other sites More sharing options...
.josh Posted July 4, 2009 Share Posted July 4, 2009 you changed all of them? Quote Link to comment https://forums.phpfreaks.com/topic/164756-weird-script-problems-please-help/#findComment-868827 Share on other sites More sharing options...
xgd Posted July 4, 2009 Author Share Posted July 4, 2009 Yea that is not the problem. If it were, then it would have said undefined variables for email and pass1 and last name too i believe. Quote Link to comment https://forums.phpfreaks.com/topic/164756-weird-script-problems-please-help/#findComment-868830 Share on other sites More sharing options...
xgd Posted July 4, 2009 Author Share Posted July 4, 2009 BTW the code is between the body tags, if that changes anything. The code goes and then below it the form. But it works it just gives weird notices. I can suppress them but that is not the point. Quote Link to comment https://forums.phpfreaks.com/topic/164756-weird-script-problems-please-help/#findComment-868831 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.