0

I am updating table when i run this query it give an error:

 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'

I dont know where the error is

4

2 回答 2

1

根据错误描述,idCampaign是字符串而不是数字,因此您需要使用引号。试试这个

 ... WHERE idCampaign = '" + id + "'"

编辑

我完全错过了你的UPDATE陈述都是错误的,我只是注意了错误信息。@RedBaron 是正确的,但您仍然必须在id. 试试这个

"UPDATE Campaign SET Name='" + req.body.Name + "', StartDate = '" + req.body.StartDate+ "' WHERE idCampaign = '" + id + "'"
于 2013-05-30T12:27:45.027 回答
1

这不是在 MySQL 中使用更新语句的方式。查看文档

广义上的查询应该是

'UPDATE Campaign SET Name=' + req.body.Name +', StartDate ='+req.body.StartDate+ ' WHERE idCampaign = ' + id
于 2013-05-30T12:29:40.680 回答