1

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

1

3 Answers 3

6

TO is a reserved word, you need to use backticks:

 DELETE FROM mail WHERE `to` = 1
Sign up to request clarification or add additional context in comments.

3 Comments

you should be able to see it as it is highlighted :)
Thank you, that worked. I didn't know it was reserved xD I was running it from a PHP file, so the query was enclosed in quotations.
It's a good habit to use backticks anyways, and quote your values (which I didn't do in the example). The query actually isn't executed with quotations, that's just PHP syntax. You may click the checkmark to the left to mark your question as resolved if you wish.
0

By adding backticks on the column name escapes in from MySQL Reserved Word

DELETE FROM mail WHERE `to`=1

Comments

-1

if the column to is not e.g. INT or DEC you should make it to = "1"

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.