Reputation: 41
.then(function (val) {
var roleId = roleArr.indexOf(val.role) + 1;
db.query(
'UPDATE employee SET role_id = ? WHERE first_name = ? AND last_name = ?;',
[roleId, val.firstname, val.lastName],
function (err) {
if (err) throw err;
console.table(val);
startPrompt();
}
);
});
This code comes from an inquirer statement. The roleID, val.firstname, and val.lastName are good variables because they are tested elsewhere in the program. The update statement is not updating though. I tried it with doublequotes around the where statement variables but that doesn't work. What am I doing wrong? The same statement works in a mysql shell.
Upvotes: -1
Views: 154
Reputation: 41
I changed the code to get the id of the name I wanted to change instead of matching a first_name and last_name.
var nameArr = [];
function Name() {
db.query(
"SELECT * FROM employee",
function (err, res) {
if (err) throw err;
for (var i = 0; i < res.length; i++) {
nameArr.push(res[i].first_name + " " + res[i].last_name);
}
});
return nameArr;
}
and
var nameId = nameArr.indexOf(val.name) + 1;
Then I used the Name() to get the choices for the inquirer question.
Upvotes: 0