Reputation: 113
Im using mysqljs and I'm trying to UPDATE a table but it shows me an error with my SQL sentence.
the documentation states that
connection.query('UPDATE users SET foo = ?, bar = ?, baz = ? WHERE id = ?', ['a', 'b', 'c', userId], function(err, results) {
// ...
});
But when I try to do it, the query creates all the variables that I'm sending to the first ?, ignorign the other ones, like this
values = [1,2,3,4,5]
sql = 'UPDATE tablename SET col1= ?, col2 = ?, col3= ?, col4 = ? WHERE col5= ?';
var query = connection.query(sql, [values], function(err) {
if (err) {
console.log(err);
throw err;
}
else {
connection.end();
}
})
But the query that gets executes is:
UPDATE tablename SET col1= 1, 2, 3, 4, col2 = ?, col3= ?, col4 = ? WHERE col5= ?';
I don't know what I'm doing wrong or what to do to fix it.
Upvotes: 0
Views: 66
Reputation: 44436
You aren't passing an array of values, you are passing an array of an array of values. Stop doing that.
Upvotes: 1