Vivid Lust Posted September 1, 2008 Share Posted September 1, 2008 Hi, here's the following code i'm using at the moment: <?php //require files require("includes/db.php"); // get form data $name = trim(strip_tags($_POST['name'])); $email = $_POST['email']; $pass = md5($_POST['pass']); $pass2 = md5($_POST['pass2']); //validate blank fields if($name == "" || $email == "" || $pass == "" || $pass2 == ""){ header('location:register.php?msg=1'); exit; } else{ if ($pass == $pass2) { $user = mysql_query("SELECT * FROM users WHERE (email='$email')"); if (mysql_num_rows($user) > 0) { header("location:register.php?msg=3"); } else { $user = mysql_query(" INSERT INTO `users` ( `email` , `pass` , `name` ) VALUES ( \"$email\", \"$pass\", \"$name\" ) "); header("location:success.php"); } } else { header("location:register.php?msg=2"); } } ?> The problem is, is that if the name or email field is blank, then the page is redirected however if a pass or pass2 is blank then it doesnt redirect and either says the passwords dont match (if only pass or pass2 is filled in); or if they are both left blank then it doesnt recognise that there is no data in the field. Please help! Thanks if you can in advanced. Quote Link to comment Share on other sites More sharing options...
valtido Posted September 1, 2008 Share Posted September 1, 2008 check on ur form where it says <input name="pass" make sure that pass says name="pass" could be a mis-spell there same goes for pass2 Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted September 1, 2008 Author Share Posted September 1, 2008 There is no misspell... Here's the code for the registration page if you need it: <?php // set variables $get = $_GET['msg']; // display relevant message based on number if($get == "1"){ $msg = "Please fill in the form correctly"; } if($get == "2"){ $msg = "Passwords didn't match"; } if($get == "3"){ $msg = "This email is already in use, please use another"; } ?> <?php echo $msg; ?> <form method="post" action="doregister.php"> Name<br /> <input type="text" name="name" /><br /> Email<br /> <input type="text" name="email" /><br /> Password<br /> <input type="password" name="pass" /><br /> Password (again)<br /> <input type="password" name="pass2" /><br /> <input type="submit" value="Register" /> </form> All fields are required. Quote Link to comment Share on other sites More sharing options...
burn1337 Posted September 1, 2008 Share Posted September 1, 2008 I would use && instead of ||, and I would make the string for your query a variable, plus I would take a look at some of your syntax (most particularly your spacing) other then that I don't exactly see why its not working, although that could very well be, because of the fact that I'm very tired Quote Link to comment Share on other sites More sharing options...
valtido Posted September 1, 2008 Share Posted September 1, 2008 basically what you are saying is that if username or email or pass or pass2 are empty then redirect them. so in ur case if any one of the fields is empty then u will always be redirected however u have said $pass= md5($_post['pass']); althought the entry is blank ur encoding this which means $pass is not going to be empty may have a longer number and also do put queries on variables to save the hassle lol like burn1337 sais Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted September 1, 2008 Author Share Posted September 1, 2008 This is getting really weird I changed the || to &&, and now with all fields blank i can hit register... and it registers the user successful... what's going on? XD Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 1, 2008 Share Posted September 1, 2008 No, you need them as || (OR). Because I'm assuming you want all fields to be filled out. If you change them to && (AND) it will only redirect if all fields are blank. Make sense? Quote Link to comment Share on other sites More sharing options...
burn1337 Posted September 1, 2008 Share Posted September 1, 2008 idk im to tired to think anymore sorry man, but I would suggest maybe not doing them all at once... idk to tired... goodnight sorry I wasn't any help .. thanks project fear for correcting me lol Quote Link to comment Share on other sites More sharing options...
valtido Posted September 1, 2008 Share Posted September 1, 2008 try this <?php //require files require("includes/db.php"); // get form data $name = trim(strip_tags($_POST['name'])); $email = $_POST['email']; $pass = md5($_POST['pass']); $pass2 = md5($_POST['pass2']); //validate blank fields if($name == "" || $email == "" ){ header('location:register.php?msg=1'); exit; } elseif($pass == "" || $pass2 == ""){ header('location:register.php?msg=1'); exit; } else{ cuntinue the same code u had..... if it doesnt work the try if its empty function Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 1, 2008 Share Posted September 1, 2008 If you run an md5 on a blank variable the result will be this: d41d8cd98f00b204e9800998ecf8427e So, don't run the md5() on the passwords until after you have checked if they are empty. Or instead of checking they are equal to nothing, check if they are equal to "d41d8cd98f00b204e9800998ecf8427e". If they are, they are empty. Quote Link to comment Share on other sites More sharing options...
valtido Posted September 1, 2008 Share Posted September 1, 2008 i did tell him that earlier lol but i assumed he had checked that lol Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted September 1, 2008 Author Share Posted September 1, 2008 Thanks to valtido, i fixed it ... <?php // get form data $name = trim(strip_tags($_POST['name'])); $email = $_POST['email']; $pass = md5($_POST['pass']); $pass2 = md5($_POST['pass2']); $passa = $_POST['pass']; $pass2a = $_POST['pass2']; //validate blank fields if($name == "" || $email == "" || $passa == "" || $pass2a == ""){ header('location:register.php?msg=1'); exit; ?> I didnt see your previous post as i was writing my other one... and I missed it they have 5 seconds in between thanks again Quote Link to comment Share on other sites More sharing options...
valtido Posted September 1, 2008 Share Posted September 1, 2008 thats good lol click the solved button tk cr 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.