MySQL查询错误 - 保留字

时间:2013-10-11 13:01:36

标签: php mysql insert

我的查询有问题,有人看到不好的东西吗?

INSERT INTO messages (subject, from, recipient, text, time)
VALUES
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')

sql:

的错误
#1064 - 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 'from, recipient, text, time) VALUES ('Welcome in King of the States!','The Gam' at line 1

5 个答案:

答案 0 :(得分:2)

from是一个mysql保留字。尝试将from放入反引号

如下所示:

`from`

答案 1 :(得分:1)

尝试做:

INSERT INTO messages (`subject`, `from`, `recipient`, `text`, `time`)
VALUES
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')

答案 2 :(得分:1)

From是mysql中的reserve关键字,请使用以下查询:

INSERT INTO `messages` (`subject`, `from`, `recipient`, `text`, `time`)
VALUES
('Welcome in King of the States!',
 'The Game','$username',
'Hello $username, 
THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')

答案 3 :(得分:0)

"INSERT INTO messages SET subject='Welcome in King of the States!',from='The Game',recipient='".$username."',text='Hello.$username', time=''";

答案 4 :(得分:0)

指令:

from是mysql中的关键字。所以你不能直接在这样的查询中使用。 你需要每次都解析它并使用反引号

from

一样使用它