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

2 Answers 2

1

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 + "'"
Sign up to request clarification or add additional context in comments.

1 Comment

i am writing this query client.query( 'UPDATE Campaign SET Name=' + req.body.Name + ', StartDate= ' +req.body.StartDate+ ' WHERE idCampaign = "' + id + '"', function(err, result) { if(err) { console.log("err found" + err); } else{ console.log(result); res.send(result[0]) } });
1

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

2 Comments

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 'WHERE idCampaign = 351adc56-c906-11e2-9cfa-74867a028324' at line 1 @RedBaron
@ana I think you should print out the query as a string, before you pass it to client.query. It will help you to debug it better. As Claudio has pointed out in his answer, you are probably missing out quotes (Especially since date is supposed to be quoted)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.