0

I get an error when sending a request to this endpoint: "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 'key = 3' at line 1" Server on node.js. Tell me where is the error?

app.put('/changetable', (request, response) => {
    if (!request.body) return response.sendStatus(400);

    const key = request.body.key;
    const col1 = request.body.col1;
    const col2 = request.body.col2;
    const col3 = request.body.col3;
    const col4 = request.body.col4;

    pool.query(`UPDATE tables set col1=?, col2=?, col3=?, col4=? WHERE key=?`, [col1, col2, col3, col4, key], function (err, result) {
        if (err) return console.log(err);
    });
    response.send(`Table edited`);
});
aleksf
  • 51
  • 4
  • 2
    https://dev.mysql.com/doc/refman/8.0/en/keywords.html#keywords-8-0-detailed-T - `tables` is a reserved word. if that's also the name of your table then a) that's a poor choice of name (for several reasons) and b) you need to put it in backticks so mysql knows it's a literal table name and not an attempt to use that reserved word as part of the statement. – ADyson Jul 26 '21 at 13:47
  • 2
    See also: [When to use single quotes, double quotes, and backticks in MySQL](https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – ADyson Jul 26 '21 at 13:47

0 Answers0