我有一个与Heroku一起部署的Node.JS应用程序,它具有简单的CRUD系统。但是,每当我使用Web应用程序本身更新行时,我都会遇到问题。
这是我的server.js文件中的UPDATE语句的代码
app.post('/logs/edit/:mobile', function(req, res){
var input = JSON.parse(JSON.stringify(req.body));
var mobile = req.params.mobile;
var data = {
last : input.last,
first : input.first,
middle : input.middle,
mobile : input.mobile,
email : input.email,
bday : input.bday,
status : input.status
};
connection.query("UPDATE logs set ? WHERE mobile = ? ",[data,mobile], function(err, rows){
if(err) console.log(err);
res.redirect('/logs');
});
});
然后这是我的日志中显示的错误
2017-06-27T02:09:55.662620+00:00 app[web.1]: { Error: ER_PARSE_ERROR: 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 ''Doe', 'Doe', 'Doe', `first` = 'John', 'John', `middle` = 'Mike', 'Mike', `mobil' at line 1
2017-06-27T02:09:55.662637+00:00 app[web.1]: at Query.Sequence._packetToError (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
2017-06-27T02:09:55.662639+00:00 app[web.1]: at Query.ErrorPacket (/app/node_modules/mysql/lib/protocol/sequences/Query.js:83:18)
2017-06-27T02:09:55.662640+00:00 app[web.1]: at Protocol._parsePacket (/app/node_modules/mysql/lib/protocol/Protocol.js:280:23)
2017-06-27T02:09:55.662641+00:00 app[web.1]: at Parser.write (/app/node_modules/mysql/lib/protocol/Parser.js:73:12)
2017-06-27T02:09:55.662642+00:00 app[web.1]: at Protocol.write (/app/node_modules/mysql/lib/protocol/Protocol.js:39:16)
2017-06-27T02:09:55.662642+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:96:28)
2017-06-27T02:09:55.662644+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-06-27T02:09:55.662644+00:00 app[web.1]: at Socket.emit (events.js:188:7)
2017-06-27T02:09:55.662646+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:176:18)
2017-06-27T02:09:55.662646+00:00 app[web.1]: at Socket.Readable.push (_stream_readable.js:134:10)
2017-06-27T02:09:55.662648+00:00 app[web.1]: --------------------
2017-06-27T02:09:55.662648+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/mysql/lib/protocol/Protocol.js:141:48)
2017-06-27T02:09:55.662649+00:00 app[web.1]: at Connection.query (/app/node_modules/mysql/lib/Connection.js:201:25)
2017-06-27T02:09:55.662650+00:00 app[web.1]: at /app/server.js:59:16
2017-06-27T02:09:55.662650+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-06-27T02:09:55.662651+00:00 app[web.1]: at next (/app/node_modules/express/lib/router/route.js:131:13)
2017-06-27T02:09:55.662652+00:00 app[web.1]: at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
2017-06-27T02:09:55.662653+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-06-27T02:09:55.662653+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:277:22
2017-06-27T02:09:55.662654+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:349:14)
2017-06-27T02:09:55.662654+00:00 app[web.1]: at param (/app/node_modules/express/lib/router/index.js:365:14)
2017-06-27T02:09:55.662655+00:00 app[web.1]: code: 'ER_PARSE_ERROR',
2017-06-27T02:09:55.662656+00:00 app[web.1]: errno: 1064,
2017-06-27T02:09:55.662657+00:00 app[web.1]: sqlState: '42000',
2017-06-27T02:09:55.662657+00:00 app[web.1]: index: 0 }
我希望有一个解决方案。
非常感谢
答案 0 :(得分:0)
据我所知,如果你向他们发送像你一样使用data
的JSON,那么MySQL版本将不会起作用。我实际上并不知道您的代码有什么问题,但是,我看到您的节点代码没问题。
我建议您直接在mysql上尝试该查询(使用控制台或工作台)