我正在更新表格,当我运行此查询时会出错:
client.query('UPDATE Campaign SET ( Name, StartDate ) VALUES ( "' +req.body.Name+ '" , "' +req.body.StartDate+ '" ) WHERE idCampaign = ' +id , function(err, result) {
if(err) {
console.log("err found" + err);
}
else{
console.log(result);
res.send(result[0])
}
});
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 '( Name, StartDate ) VALUES ( "" , "" ) WHERE idCampaign = 89126b2d-c906-11e2-9cf'
我不知道错误在哪里
答案 0 :(得分:1)
根据错误说明,idCampaign
是字符串而不是数字,因此您需要使用引号。试试这个
... WHERE idCampaign = '" + id + "'"
修改强>
我完全错过了你的UPDATE
声明都错了,我只是注意了错误信息。 @RedBaron是正确的,但您仍然必须使用id
上的引号。试试这个
"UPDATE Campaign SET Name='" + req.body.Name + "', StartDate = '" + req.body.StartDate+ "' WHERE idCampaign = '" + id + "'"
答案 1 :(得分:1)
这不是MySQL中如何使用更新语句。查看Documentation
一般来说,查询应该像
'UPDATE Campaign SET Name=' + req.body.Name +', StartDate ='+req.body.StartDate+ ' WHERE idCampaign = ' + id