Jump to content
MakeWebGames

learning php have an error.


Beryne

Recommended Posts

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...