Sean Anderson
Sean Anderson

Reputation: 660

Another MySQL syntax error using INSERT INTO

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?

Upvotes: 2

Views: 3953

Answers (4)

Nulik
Nulik

Reputation: 7390

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

Upvotes: 1

Michael Berkowski
Michael Berkowski

Reputation: 270767

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')

Upvotes: 2

Joe Stefanelli
Joe Stefanelli

Reputation: 135918

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')

Upvotes: 0

Mark Baker
Mark Baker

Reputation: 212522

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.

Upvotes: 5

Related Questions