Jump to content

Database problem


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) . "')")

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...