开发者

PHP/MySQL Insert [duplicate]

This question already has an answer here: Syntax error due to using a reserved word as a table or column name in MySQL (1 answer) Closed 8 years ago.

Ok I have been using PHP + MySQL for a while so I consider myself proficient. I have made my fair share of syntactical mistake开发者_运维百科s in the past but this is honestly pissing me off:

http://img251.imageshack.us/img251/3760/fubar.png

If anyone can tell me why this simple statement isn't working I would be greatly appreciative.


Actually I do see 1 error..."Option" is a reserved word. wrap it in backtics : `Option` or better yet, change the column name to something that's not a reserved word.


Use backticks for 'option'.

INSERT INTO poll (`Option`) VALUES ('Stuff')


Looking at the code you're trying to insert what comes from $_POST['survey'], so your insert should look like this:

$vote = $_POST['survey'];

// connect to db

mysql_query(sprintf(
    "INSERT INTO poll (`Option`) VALUES ('%s')", 
    mysql_real_escape_string($vote)
);

Also note that "option" is a reserved keyword and needs to be inside backticks.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜