Below is the snippet of my code:
app.put("/update/:id", (req, res) => {
const userID = req.params.id;
const sql = "UPDATE quotes SET `first_name` = ?, `last_name` = ?, `company` = ?, `email` = ?, `phone` = ? WHERE id = ?"
const values = [my values]
db.query(sql, [...values, userID], (err, data) => {
if (err) return res.send(err)
return res.json(data)
})
})
I am encountering the following error message:
{
"code": "ER_BAD_NULL_ERROR",
"errno": 1048,
"sqlState": "23000",
"sqlMessage": "Column 'first_name' cannot be null",
"sql": "UPDATE quotes SET `first_name` = NULL, `last_name` = NULL, `company` = NULL, `email` = NULL, `phone` = NULL WHERE id = '2'"
}
I aim to update only the first_name
field without affecting other fields and their existing records.