geek@02 Posted February 18, 2012 Share Posted February 18, 2012 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 More sharing options...
boen_robot Posted February 18, 2012 Share Posted February 18, 2012 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 More sharing options...
geek@02 Posted February 18, 2012 Author Share Posted February 18, 2012 Big thanks mate, it worked -Kasun Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.