chris
chris

Reputation: 36937

PHP mySQL sanity check, query error

Trying to do a simple insert, and this one line is giving me issues. I can't for the life of me see whats wrong with it. So its gotta be something superbly simple that I need another pair of eyes to notice for me apparently.

mysql_query("INSERT INTO ".MLIST."(email, when) VALUES('".mysql_real_escape_string($_POST['email'])."', '".$timeNow."')") or die(mysql_error());

the error is

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 ''email', 'when') VALUES('[email protected]', '2012-06-11 03:58:55')' at line 1

Upvotes: 1

Views: 432

Answers (2)

Tepken Vannkorn
Tepken Vannkorn

Reputation: 9723

From my experience, I used to get this error even my SQL syntax is right. After checking for what causes the problem, I found my fault at another page which sends the data to the page I'm standing on.

Upvotes: 0

scriptin
scriptin

Reputation: 3120

WHEN is a keyword - place it inside backticks:

INSERT INTO ... (`email`, `when`) ...

Upvotes: 8

Related Questions