2

MySQL is returning a syntax error for this query (via PHP):

INSERT INTO links (link, name, desc, category) 
VALUES ('www.contoso.com', 'Contoso', 'My Website', 'Vanity')

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 'desc, category) VALUES ('www.contoso.com', 'Contoso', 'My Website', 'Vani' at line 1

I see nothing wrong with it. What gives?

1
  • As a general rule don't use reserved words for table or column names. It saves a lot of hassle. Commented Jan 10, 2012 at 21:30

4 Answers 4

5

DESC is a MySQL reserved word... if you want to use it as a column name you must enclose it in backticks

The actual error message after the word "near" gives an indication of exactly where in your SQL statement the parser believes the error to be... in this case, at the word "desc". That can often be a good guide to diagnosing the problem.

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

4 Comments

In my noobness I didn't know it was a reserved word. Thanks!
I had tried ticking all the column names at one time and it didn't work. I changed it to "description" instead, and it worked.
@user513905 - make sure you used backticks (`) rather than single quotes (')
Wow, that would be the difference. I didn't pay attention to that little detail.
2

desc is a MySQL reserved keyword. It must be enclosed in backquotes as

INSERT INTO links (link, name, `desc`, category) VALUES ('www.datavirtue.com', 'Data Virtue', 'My Website', 'Vanity')

Comments

1

"desc" is a reserved word. Use "description"

Comments

0

DESC is a reserved word and must be escaped with backticks.

INSERT INTO links 
    (link, name, `desc`, category) 
    VALUES 
    ('www.datavirtue.com', 'Data Virtue', 'My Website', 'Vanity')

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.