klp klp - 2 months ago 44
MySQL Question

How to update multiple columns in mysql using nodejs

How to update the multiple columns in MySQL using node.js:

var query = 'UPDATE employee SET profile_name = ? WHERE id = ?';
connection.query(query,[req.name,req.id] function (error, result, rows, fields) {


but I have to update
profile_name
,
phone,email
,
country
,
state
,
address
at once.

How can I do that, can anyone suggest.

Answer

Simply add all columns in set:

var query = 'UPDATE employee SET profile_name = ?, phone =?, .. WHERE id=?';

connection.query(query,[req.name,req.phone,...,req.id] function (error, result, rows, fields) {