4

For the life of me I can't get this insert query to work.

mysql_connect("**host**", "**username**", "**password**") or error("Could not connect: ".mysql_error());
mysql_select_db("**db_name**");
$db = mysql_query("INSERT INTO `pass_reset` (id,status,key,email) VALUES ('','0','$key','$email')");

It returns this error:

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 'key,email) VALUES ('','0','','')' at line 1

Could someone help me with this? I'm literally pulling my hair out over this simple query.

0

4 Answers 4

10

Try the following:

$db = mysql_query("INSERT INTO `pass_reset` (id,status,`key`,email) VALUES ('','0','$key','$email')");

Because key is a reserved word by MySQL, you must escape it with the backticks ``

Sign up to request clarification or add additional context in comments.

3 Comments

It is a keyword, you could say. Haha. Ha. I'll be going now.
@Shef, I tend to always back-tick all my field-/tablenames solves a lot of unknown problems!
@Nideo: So do I. I am blamed so often for that by coders who put much more weigh on readability and forget about functionality. :)
3

KEY is a reserved word in MySQL, so you'd have to escape it with back ticks.

Comments

0

Maybe try enclosing the column names with the grave accent?

(`id`,`status`,`key`,`email`)

Comments

-1

dont put php variable in '', it will surely work man

$db = mysql_query("INSERT INTO `pass_reset` (id,status,key,email) VALUES ('','0',$key,$email)");

Or

 $db = mysql_query("INSERT INTO `pass_reset` (id,status,key,email) VALUES ('0',$key,$email)");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.