Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP/MySQL Insert Query

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.

like image 957
Spencer Avatar asked Sep 07 '25 04:09

Spencer


2 Answers

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 ``

like image 106
Shef Avatar answered Sep 08 '25 18:09

Shef


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

like image 22
Joe Stefanelli Avatar answered Sep 08 '25 18:09

Joe Stefanelli