Reputation: 13
I have this bit of SQL
that always returns an error, though I can't find why it is returning the error. I have connected to the database with no errors. I'm running PHP 5.2.17
, MySQL 5.5.25a
, and Apache 2.4.2.
The SQL
:
DELETE FROM mail WHERE to=1
The 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 'to=1' at line 1
Upvotes: 1
Views: 233
Reputation: 511
By adding backticks
on the column name escapes in from MySQL Reserved Word
DELETE FROM mail WHERE `to`=1
Upvotes: 0
Reputation: 102774
TO
is a reserved word, you need to use backticks:
DELETE FROM mail WHERE `to` = 1
Upvotes: 6
Reputation: 1475
if the column to is not e.g. INT or DEC you should make it to = "1"
Upvotes: -1