Reputation: 31
When I run some php code I've written, I get the following message:
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 'condition, price, name, email) VALUES('Fake Title', 'Fake Subhead', 'Fake Author' at line 1
I do not see anything wrong with my syntax, however, which is like:
mysql_query("INSERT INTO table (x1, x2, x3) VALUES('$y1', '$y2', '$y3')");
Upvotes: 0
Views: 99
Reputation: 7597
If you're getting that message in phpMyAdmin, my experience has been that it starts displaying your error at the point at which your syntax goes awry. Which in your case seems to be at the word "condition". Which (like @pf.me pointed out) is a reserved word in MySQL.
You'd get the same error, if you changed your column to "select" or "join".
Here's a list of reserved words for MySQL 5.1 (not sure of the version you're using) http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html
Upvotes: 2
Reputation: 13649
condition isn't allowed as a column name (it's a reserved keyword), you need to quote it with backticks (`) to "bypass":
INSERT INTO table_name (`condition`, price, name, email) VALUES (...)
Check it out for more information: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
Upvotes: 6
Reputation: 125476
its seems that you you need to wrap your column name ('x1', 'x2', 'x3')
Upvotes: 0
Reputation: 1306
One of the $y's has ' in the string, and it breaks the query. Like $y = "John's example".
Upvotes: 0
Reputation: 18531
Simply echo out your full SQL query before it is executed and you will find what the problem is. Check the values of your $y1, $y2, $y3 parameters.
Upvotes: 2