Reputation: 660
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
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
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
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