开发者

Odd PHP Error Message

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


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


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.


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


One of the $y's has ' in the string, and it breaks the query. Like $y = "John's example".


its seems that you you need to wrap your column name ('x1', 'x2', 'x3')

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜