破解MySQL查询

时间:2014-05-07 18:34:38

标签: mysql insert

MySQL在执行SQL查询时一直报告错误。一切看起来都对我来说,但我已经看了大约一个小时了。

"INSERT INTO invoices 

(total, generated, account, market, status, name, hash) 

VALUES 

('$total', Now(), '$aid', '$mid', '$name', 'Active', '$hash')"

错误

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 'desc, account, market, status, name, hash) VALUES ('499.99', NOW(), 'System gene' at line 1 (SQL: INSERT INTO invoices (total, generated, desc, account, market, status, name, hash) VALUES ('499.99', NOW(), 'System generated invoice during Market setup/activation.', '6', '9', 'Zac Company - Chandler', 'Active', 'b0521f6668cb87de009866b67b25b458')

我认为这是一个简单的解决方案,需要新鲜的眼睛。

1 个答案:

答案 0 :(得分:1)

它在那里

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近'desc,account,

desc是一个保留字,因此必须使用后引号进行转义

`desc`

此外,total是一个数字列;所以不需要引用它

您的SQL查询应如下所示

INSERT INTO invoices (total, generated, `desc`, account, market, status, name, hash) 
                                          <--Here
VALUES (499.99, NOW(), 'System generated invoice during Market setup/activation.',
'6', '9', 'Active', 'Zac Company - Chandler',  'b0521f6668cb87de009866b67b25b458')