'SQL Update statement no longer working after changing names
I changed some of the names in my update query and now it no longer works ;(. I get this error.
sqlMessage: "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id = 42' at line 1",
sqlState: '42000',
index: 0,
sql: "UPDATE developers SET name = 'eyo', absent = '1', WHERE id = 42"
I changed slack_id into Name, changed everything like normal, but still doesn't work.
// UPDATE
app.put("/update", (req, res) => {
const id = req.body.id;
const name = req.body.name;
const absent = req.body.absent;
db.query("UPDATE developers SET name = ?, absent = ? WHERE id = ?" ,[name, absent, id],
(err, result) => {
if (err) {
console.log(err);
} else {
res.send(result);
console.log(result)
}
}
);
});
This Update redirects to my Axios.put
const updateDeveloper = () => {
try {
setSuccessMessageUpdate('');
setErrorMessageUpdate('');
Axios.put(`${url}/update`, { name: name, absent: absent, id: props.id }).then(
(response) => {
return (
{
id: props.id,
name: props.name,
slack_id: props.slack_id,
absent: props.absent,
selected: props.selected,
}
)
}
);
setSuccessMessageUpdate(`successfully updated developer `);
} catch (err) {
setErrorMessageUpdate('something went wrong');
}
};
I would say the rest of the code is irrelevant because the error is clearly mentioning a database issue. Maybe its a type error? I can't see it.
Solution 1:[1]
Never-mind I found the issue already. Seems the code is fine but after I saved I forgot to restart node, my bad.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wake |
