omglolnub Posted May 22, 2008 Share Posted May 22, 2008 I've been trying to fix this code for a couple of days.It used work but after I tried to add checking for things like account already exists, email already in user, passwords do not match and such it fail to keep working. It does not error out until the end (the query for Char) but the checking seems to not work (can still create two accounts with same name/email and can enter different passwords. <?php include 'DBopen.php'; $Acc = $_POST['acc']; $Pwd1 = md5($_POST['pwd1']); $Pwd2 = md5($_POST['pwd2']); $Email1 = $_POST['email1']; $Email2 = $_POST['email2']; $Class = $_POST['class']; $Gender = $_POST['gender']; if ($Pwd1 != $Pwd2){ setcookie('msg','Passwords do not match!',0); header ( "http://gunners.freehostia.com/CreateAccount.php" ); } if ($Email1 != $Email2){ setcookie('msg','Emails do not match!',0); header ( "http://gunners.freehostia.com/CreateAccount.php" ); } $sql = "SELECT * FROM Player WHERE Acc = '$Acc'"; $result = mysql_query($sql) or die ('Errrrror'); $rows = mysql_num_rows($result); if ($rows == 1){ setcookie('msg','Account name already in use.',0); header ( "http://gunners.freehostia.com/CreateAccount.php" ); }; $sql2 = "SELECT * FROM Player WHERE Email = '$Email1'"; $result2 = mysql_query($sql2) or die ('Nope'); $rows1 = mysql_num_rows($result2); if ($rows2 == 1){ setcookie('msg','Email already in use!',0); header ( "http://gunners.freehostia.com/CreateAccount.php" ); }; if ($Class = 'class1'){ $Str = 3; $Int = 3; $Dex = 2; }; if ($Class = 'class2'){ $Str = 3; $Int = 2; $Dex = 3; }; if ($Class = 'class3'){ $Str = 3; $Int = 3; $Dex = 2; }; if ($Class = 'class4'){ $Str = 2; $Int = 3; $Dex = 2; }; if ($Class = 'class5'){ $Str = 3; $Int = 2; $Dex = 3; }; if ($Class = 'class6'){ $Str = 2; $Int = 3; $Dex = 3; }; $query = "INSERT INTO Player ( Acc, Pwd, Email, Admin) VALUES ( '$Acc', '$Pwd1', '$Email1', '0')"; mysql_query ($query) or die ('Error you fucked up'); $query2 = "INSERT INTO Char ( Name, Class, Gender, Str, Int, Dex, BStr, BInt, BDex) VALUES ( '$Acc', '$Class', '$Gender', '$Str', '$Int', '$Dex', '0', '0', '0')"; mysql_query ($query2) or die ('Error you fucked up'); setcookie('msg','Account Created!,',0); //header ("Location: http://gunners.freehostia.com"); echo "$query2"; ?> Thanks in advance. ~The Nub~ Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/ Share on other sites More sharing options...
LooieENG Posted May 22, 2008 Share Posted May 22, 2008 Don't know if this has anything to do with it, but you check if $rows2 is 1, but $rows2 is never defined Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547014 Share on other sites More sharing options...
omglolnub Posted May 22, 2008 Author Share Posted May 22, 2008 Thanks, changed that but no over all change in the way it works :S. Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547065 Share on other sites More sharing options...
samuraitux Posted May 22, 2008 Share Posted May 22, 2008 have you tried using the string compare function? might help. Also not sure but it looks like all your if statements have a single = sign. Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547079 Share on other sites More sharing options...
omglolnub Posted May 22, 2008 Author Share Posted May 22, 2008 I may be misstaken but if you checking for != isnt it only one "="? Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547520 Share on other sites More sharing options...
jonsjava Posted May 22, 2008 Share Posted May 22, 2008 (supposedly) Fixed code: <?php include 'DBopen.php'; $Acc = $_POST['acc']; $Pwd1 = md5($_POST['pwd1']); $Pwd2 = md5($_POST['pwd2']); $Email1 = $_POST['email1']; $Email2 = $_POST['email2']; $Class = $_POST['class']; $Gender = $_POST['gender']; if ($Pwd1 != $Pwd2){ setcookie('msg','Passwords do not match!',0); header ( "http://gunners.freehostia.com/CreateAccount.php" ); } if ($Email1 != $Email2){ setcookie('msg','Emails do not match!',0); header ( "http://gunners.freehostia.com/CreateAccount.php" ); } $sql = "SELECT * FROM Player WHERE Acc = '$Acc'"; $result = mysql_query($sql) or die ('Errrrror'); $rows = mysql_num_rows($result); if ($rows == 1){ setcookie('msg','Account name already in use.',0); header ( "http://gunners.freehostia.com/CreateAccount.php" ); }; $sql2 = "SELECT * FROM Player WHERE Email = '$Email1'"; $result2 = mysql_query($sql2) or die ('Nope'); $rows1 = mysql_num_rows($result2); if ($rows1 == 1){ setcookie('msg','Email already in use!',0); header ( "http://gunners.freehostia.com/CreateAccount.php" ); }; if ($Class == 'class1'){ $Str = 3; $Int = 3; $Dex = 2; }; if ($Class == 'class2'){ $Str = 3; $Int = 2; $Dex = 3; }; if ($Class == 'class3'){ $Str = 3; $Int = 3; $Dex = 2; }; if ($Class == 'class4'){ $Str = 2; $Int = 3; $Dex = 2; }; if ($Class == 'class5'){ $Str = 3; $Int = 2; $Dex = 3; }; if ($Class == 'class6'){ $Str = 2; $Int = 3; $Dex = 3; }; $query = "INSERT INTO Player ( Acc, Pwd, Email, Admin) VALUES ( '$Acc', '$Pwd1', '$Email1', '0')"; mysql_query ($query) or die ('Error you fucked up'); $query2 = "INSERT INTO Char ( Name, Class, Gender, Str, Int, Dex, BStr, BInt, BDex) VALUES ( '$Acc', '$Class', '$Gender', '$Str', '$Int', '$Dex', '0', '0', '0')"; mysql_query ($query2) or die ('Error you fucked up'); setcookie('msg','Account Created!,',0); //header ("Location: http://gunners.freehostia.com"); echo "$query2"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547522 Share on other sites More sharing options...
omglolnub Posted May 22, 2008 Author Share Posted May 22, 2008 Nope absolutely no change :-S. Actually that party of the code was working anyway. Its the query thats inserting to to table "Char" thats failing. Also is letting me user the same username/email twice and different Passwords/emails in the two fields still. Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547536 Share on other sites More sharing options...
omglolnub Posted May 22, 2008 Author Share Posted May 22, 2008 After changing the error checking to something useful this is what I'm getting. Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Char ( Name, Class, Gender, Str, Int, Dex, BStr, BInt, BDex) VAL Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547561 Share on other sites More sharing options...
jonsjava Posted May 22, 2008 Share Posted May 22, 2008 $query2 = "INSERT INTO `Char` ( `Name`, `Class`, `Gender`, `Str`, `Int`, `Dex`, `BStr`, `BInt`, `BDex`) VALUES ( '$Acc', '$Class', '$Gender', '$Str', '$Int', '$Dex', '0', '0', '0')"; Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547575 Share on other sites More sharing options...
omglolnub Posted May 22, 2008 Author Share Posted May 22, 2008 Yea, the query works now! However I still cant get the checking to work :S. Sorry I'm a noob. Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-547754 Share on other sites More sharing options...
omglolnub Posted May 24, 2008 Author Share Posted May 24, 2008 Anyone? Anyone? Please? Bump? Quote Link to comment https://forums.phpfreaks.com/topic/106708-account-creation-help/#findComment-548666 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.