Beryne Posted July 15, 2011 Posted July 15, 2011 Im watching tutorials on how to program in php. I got to the point to where i create a registration page but when i go to register i get this error Notice: Undefined index: password in C:\xampp\htdocs\game\register.php on line 13 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 ''user' WHERE 'username' ='knjj2008'' at line 1 here is the code <?php include("functions.php"); connect(); ?> <?php if(isset($_POST['register'])){ $username = protect($_POST['username']); $password = protect($_POST['password']); $email = protect($_POST['email']); if(strlen($username) > 20){ echo "Username must be less than 20 characters!"; }elseif(strlen($email) > 100){ echo "E-mail must be less than 100 characters!"; }else{ $register1 = mysql_query("SELECT 'id' FROM 'user' WHERE 'username' ='$username'") or die(mysql_error()); $register2 = mysql_query("SELECT 'id' FROM 'user' WHERE 'email' ='$email'") or die(mysql_error()); if(mysql_num_rows($register1) > 0){ echo "That username is already in use!"; }elseif(mysql_num_rows($register2) > 0){ echo "That e-mail adress is already in use!"; }else{ $ins1 = mysql_query("INSERT INTO 'stats' ('gold','attack','defense','food') VALUES (100,10,10,100)") or die(mysql_error()); $ins2 = mysql_query("INSERT INTO 'unit' ('worker','farmer','warrior','defender') VALUES (5,5,0,0)") or die(mysql_error()); $ins3 = mysql_query("INSERT INTO 'user' ('username','password','email') VALUES ('$username','".md5($password)."','$email')") or die (mysql_error()); $ins4 = mysql_query("INSERT INTO 'weapon' ('sword',shield') VALUES (0,0)") or die(mysql_error()); echo "You have registered!"; } } } ?> Register <br /> <form action="register.php" method="POST"> Username: <input type="text" name="username"/><br /><br /> Password: <input type="password" name="username"/><br /><br /> E-mail: <input type="text" name="email"/><br /><br /> <input type="submit" name="register" value="Register"/> </form> Quote
Lithium Posted July 15, 2011 Posted July 15, 2011 Password: <input type="password" name="username"/><br /><br /> Should be Password: <input type="password" name="password"/><br /><br /> Quote
Danny696 Posted July 15, 2011 Posted July 15, 2011 Your querys are wrong. Around the colums and tables, it should be a ` not a ' Quote
Beryne Posted July 15, 2011 Author Posted July 15, 2011 I fixed the line Lithium pointed out, but now i get this error Register 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 ''user' WHERE 'username' ='beryne'' at line 1 I am not sure what you mean Danny? Quote
Danny696 Posted July 15, 2011 Posted July 15, 2011 Take your first query: $register1 = mysql_query("SELECT 'id' FROM 'user' WHERE 'username' ='$username'") or die(mysql_error()); around the colum, and table, table being user and columns being id and username, they all have a ' (apostrophe) whereas they need a ` (dunno its name) Quote
Beryne Posted July 15, 2011 Author Posted July 15, 2011 Your querys are wrong. Around the colums and tables, it should be a ` not a ' NVM :p thanks Quote
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.