Can't seem to get the syntax correct for the UPDATE SQL command with my express API call when using string interpolation. Here is the error below. In addition I am using this with react-admin and I am not resolving the Promise properly. grr.
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 '? , ['6']' at line 1
// Update a user
router.put("/users/:id", async (req, res) => {
try {
const { id } = req.params; // WHERE
console.log(req.params);
const { firstName, lastName, email } = req.body // SET
// What if we do not know how many params are updated plus this is very messy sql
const [rows, fields] = await pool.query(
`UPDATE user SET firstName = ?, lastName = ?, email = ? WHERE id = ?, ['${firstName}', '${lastName}', '${email}', '${id}']`);
res.json(rows, fields);
} catch (err) {
console.error(err.message);
}
});