2013-10-11 31 views
1

我有查询问题,有人看到不好的东西?从SQLMySQL查询错误 - 保留字

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

错误:

#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 
+4

'FROM'是SQL的保留字。您可以使用反引号将其转义,或更改列名称。 – andrewsi

+0

Ok -...这将是非常的编辑:DD我会尝试 –

+0

确定它的工作..我改变了“从”到“发件人”和“为”到“收件人”谢谢你;) –

回答

2

from是一个MySQL保留字。试着将from在反引号

象下面这样:

`from` 
+1

是的,它的工作:) –

+0

你需要接受答案,而不是改变标题:) – WebNovice

+0

http://stackoverflow.com/help/accepted-answer – WebNovice

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') 
1

从是在mysql储备关键字因此使用下面的查询:

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') 
0
"INSERT INTO messages SET subject='Welcome in King of the States!',from='The Game',recipient='".$username."',text='Hello.$username', time=''"; 
+1

这将无法正常工作 - 您仍然需要逃避FROM。 – andrewsi

+0

从字段中删除添加更改字段名称 – Punitha

0

指令:

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

使用它像from