ana
ana

Reputation: 653

unable to remove SQL syntax in UPDATE query

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

Upvotes: 0

Views: 336

Answers (2)

Claudio Redi
Claudio Redi

Reputation: 68410

According the error description, idCampaign is a string and not a number so you need to use quotes. Try with this

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

EDIT

I totally missed that your UPDATE statement was all wrong, I just paid attention to the error message. @RedBaron is correct but you still have to use the quotes on id. Try with this

"UPDATE Campaign SET Name='" + req.body.Name + "', StartDate = '" + req.body.StartDate+ "' WHERE idCampaign = '" + id + "'"

Upvotes: 1

RedBaron
RedBaron

Reputation: 4755

That is not how an update statement is used in MySQL. Look at the Documentation

Broadly the query should be like

'UPDATE Campaign SET Name=' + req.body.Name +', StartDate ='+req.body.StartDate+ ' WHERE idCampaign = ' + id

Upvotes: 1

Related Questions