expressjs mysql update error
I use expressjs with node-mysql module. I got this error when I post to update action
/Users/mac/node_modules/mysql/lib/mysql/client.js:106
cb(err);
^
TypeError: string is not a function
at String.CALL_NON_FUNCTION (native)
at Query.<anonymous> (/Users/mac/node_modules/mysql/lib/mysql/client.js:106:9)
at Query.emit (events.js:64:17)
at Query._handlePacket (/Users/mac/node_modules/mysql/lib/mysql/query.js:35:12)
at Client._handlePacket (/Users/mca/node_modules/mysql/lib/mysql/clie开发者_StackOverflownt.js:294:14)
at Parser.<anonymous> (/Users/mac/node_modules/mysql/lib/mysql/client.js:83:14)
at Parser.emit (events.js:64:17)
at /Users/mac/node_modules/mysql/lib/mysql/parser.js:75:14
at Parser.write (/Users/mac/node_modules/mysql/lib/mysql/parser.js:580:7)
at Socket.<anonymous> (/Users/mca/node_modules/mysql/lib/mysql/client.js:63:16)
I use this action:
app.post('/post/:id/edit', function(req, res){
var id = req.params.id;
var query = client.query(
'UPDATE '+POST,
'SET title = ?, text = ?',
[req.body.title, req.body.text ],
' WHERE id='+id
);
res.redirect('/');
});
What's wrong?
var query = client.query(
'UPDATE '+POST +
' SET title = ?, text = ?' +
' WHERE id='+id,
[req.body.title, req.body.text ]
);
You were using ,
instead of +
You want to concatenate all your string parts, then pass your array of parameters at the end.
精彩评论