Jump to content

Database problem


geek@02

Recommended Posts

Hi!i used below code to retrieve a new username and pass from the user and insert them into a MySql database. But the code gives me this error when i used "robin" to register a new user:

"Unknown column 'robin' in 'field list'"

. What might be the problem? Thanks.

<?phpsession_start();$newusername = $_POST["newusername"]; // This is the inputted username from the form in Login.html$newpassword = $_POST["newpassword"]; // This is the inputted password from the form in Login.htmlmysql_connect('localhost'); // *** INSERT YOUR DATABSE INFORMATION HERE ***mysql_select_db('test') or die('Could not select database');// $result = mysql_query("SELECT username, password FROM bkmark_users"); // Get data from username and password fieldsecho $newusername."<br>";echo $newpassword."<br>";mysql_query("INSERT INTO bkmark_users(username, password) VALUES($newusername, $newpassword) ") or die(mysql_error());?>

Link to comment
Share on other sites

You must put single quotes around the strings in order to denote them as strings. Otherwise, they're treated as names of columns that contain the value to be inserted.While you're at it, you might as well escape it properly for SQL's sake. So

mysql_query("INSERT INTO bkmark_users(username, password) VALUES('" . mysql_real_escape_string($newusername) . "','" . mysql_real_escape_string($newpassword) . "')")

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...