Chidori Soul Posted June 29, 2010 Share Posted June 29, 2010 Alright, so I'm doing a pure dynamic AJAX site, and i've been on a register script for 2 days now, and for some reason, something about it makes it weird. <?php session_start(); require('require/connect.php'); require('require/clean_code.php'); $name = safe($_GET['user']); if(isset($_GET['user'])) { $pass = safe($_GET['pass']); $email = safe($_GET['email']); $gender = safe($_GET['gender']); $class = safe($_GET['type']); if($name=='') { echo "Please enter a name."; } elseif($pass=='') { echo "Please enter a password."; } elseif($email=='') { echo "Please enter an email."; } elseif($gender != "Male" && $gender != "Female") { echo "Please choose a legit gender."; } elseif($class != "Warrior" && $class != "Mage") { echo "Please choose a legit class."; } else { $q = mysql_query("SELECT * FROM `users` WHERE `name`='".$name."'"); $c = mysql_num_rows($q); $q1 = mysql_query("SELECT * FROM `users` WHERE `email`='".$email."'"); $c2 = mysql_num_rows($q1); if($c > '0') { echo "This name is already in use."; } elseif($c1 > '0') { echo "This email is already in use."; } else { $pass2 = sha1($pass); mysql_query("INSERT INTO `users` (`name`, `pass`, `email`, `type`, `gender`) VALUES ('".$name."', '".$pass2."', '".$email."', '".$class."', '".$gender."')") or die(mysql_error()); echo "You have successfuly registered, ".$name."."; } } } else { ?> <head> <script type='text/javascript' src='require/jquery.js'></script> <script type='text/javascript' src='require/main.js'></script> <script type='text/javascript'> function function1() { var user = window.document.reg.user.value; var pass = window.document.reg.password.value; var email = window.document.reg.email.value; var gender = window.document.reg.gender.value; var class = window.document.reg.class.value; var url = "reg.php?user=" + user + "&pass=" + pass + "&email=" + email + "&gender=" + gender + "&type=" + class + ""; loadlink(url); } </script> </head> TestRegister <form name='reg' onsubmit='return function1();'> <table width='98%' style='border: 1px solid black;' valign='top' align='center'> <tr><td width='30%' style='border: 1px solid black;'>Username</td><td width='70%' style='border: 1px solid black;'><input type="text" name="user"></td></tr> <tr><td width='30%' style='border: 1px solid black;'>Password</td><td width='70%' style='border: 1px solid black;'><input type="password" name="password"></td></tr> <tr><td width='30%' style='border: 1px solid black;'>Email</td><td width='70%' style='border: 1px solid black;'><input type="text" name="email"></td></tr> <tr><td width='30%' style='border: 1px solid black;'>Gender</td><td width='70%' style='border: 1px solid black;'><select name="gender"><option value="Male">Male</option><option value="Female">Female</option></select></td></tr> <tr><td width='30%' style='border: 1px solid black;'>Class</td><td width='70%' style='border: 1px solid black;'><select name="class"><option value="Warrior">Path Of Swordsmen</option><option value="Mage">Guidance Of Magician</option></select></td></tr> <tr><td width='30%' colspan='2' style='border: 1px solid black;'><input type='submit' name='submit' value='Register!' onclick='function1();'></td></tr> </table> </form> <?php } ?> If you tried this, it would be successful, but it would say that the username is already registered, so it really lies. Can someone point out the error on this AJAX/PHP? Quote Link to comment Share on other sites More sharing options...
trq Posted June 29, 2010 Share Posted June 29, 2010 Strings need to be surrounded by quotes in php, not numbers. Quote Link to comment Share on other sites More sharing options...
Chidori Soul Posted June 29, 2010 Author Share Posted June 29, 2010 <?php session_start(); require('require/connect.php'); require('require/clean_code.php'); $name = safe($_GET['user']); if(isset($_GET['user'])) { $pass = safe($_GET['pass']); $email = safe($_GET['email']); $gender = safe($_GET['gender']); $class = safe($_GET['type']); if($name=='') { echo "Please enter a name."; } elseif($pass=='') { echo "Please enter a password."; } elseif($email=='') { echo "Please enter an email."; } elseif($gender != "Male" && $gender != "Female") { echo "Please choose a legit gender."; } elseif($class != "Warrior" && $class != "Mage") { echo "Please choose a legit class."; } else { $q = mysql_query("SELECT * FROM `users` WHERE `name`='".$name."'"); $c = mysql_num_rows($q); $q1 = mysql_query("SELECT * FROM `users` WHERE `email`='".$email."'"); $c1 = mysql_num_rows($q1); if($c > 0) { echo "This name is already in use."; } elseif($c1 > 0) { echo "This email is already in use."; } else { $pass2 = sha1($pass); mysql_query("INSERT INTO `users` (`name`, `pass`, `email`, `type`, `gender`) VALUES ('".$name."', '".$pass2."', '".$email."', '".$class."', '".$gender."')") or die(mysql_error()); echo "You have successfuly registered, ".$name."."; } } } else { ?> <head> <script type='text/javascript' src='require/jquery.js'></script> <script type='text/javascript' src='require/main.js'></script> <script type='text/javascript'> function function1() { var user = window.document.reg.user.value; var pass = window.document.reg.password.value; var email = window.document.reg.email.value; var gender = window.document.reg.gender.value; var class = window.document.reg.class.value; var url = "reg.php?user=" + user + "&pass=" + pass + "&email=" + email + "&gender=" + gender + "&type=" + class + ""; loadlink(url); } </script> </head> TestRegister <form name='reg' onsubmit='return function1();'> <table width='98%' style='border: 1px solid black;' valign='top' align='center'> <tr><td width='30%' style='border: 1px solid black;'>Username</td><td width='70%' style='border: 1px solid black;'><input type="text" name="user"></td></tr> <tr><td width='30%' style='border: 1px solid black;'>Password</td><td width='70%' style='border: 1px solid black;'><input type="password" name="password"></td></tr> <tr><td width='30%' style='border: 1px solid black;'>Email</td><td width='70%' style='border: 1px solid black;'><input type="text" name="email"></td></tr> <tr><td width='30%' style='border: 1px solid black;'>Gender</td><td width='70%' style='border: 1px solid black;'><select name="gender"><option value="Male">Male</option><option value="Female">Female</option></select></td></tr> <tr><td width='30%' style='border: 1px solid black;'>Class</td><td width='70%' style='border: 1px solid black;'><select name="class"><option value="Warrior">Path Of Swordsmen</option><option value="Mage">Guidance Of Magician</option></select></td></tr> <tr><td width='30%' colspan='2' style='border: 1px solid black;'><input type='submit' name='submit' value='Register!' onclick='function1();'></td></tr> </table> </form> <?php } ?> I did that, and still, the same result, I think it has something to do with my AJAX. Quote Link to comment Share on other sites More sharing options...
Stooney Posted June 29, 2010 Share Posted June 29, 2010 I would print out the query and make sure it contains the expected data. Check your database for a user entry that's blank. The script could be losing the username somewhere and trying to insert a blank user, which would be used after the first try. Quote Link to comment Share on other sites More sharing options...
Chidori Soul Posted July 1, 2010 Author Share Posted July 1, 2010 Well, from my experience using it, it enters the user, then reruns the script and says that the username is taken. Quote Link to comment Share on other sites More sharing options...
jonndoe45 Posted July 20, 2010 Share Posted July 20, 2010 put an error_log statement in your script to dump out the query, then run the query in mysql query browser 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.