Help, please, to understand why the error takes off:

ER_PARSE_ERROR: You have an error in your SQL syntax; check the syntax to use mySQL? (1,?), (1,?) 'at line

And, perhaps, my 'crutches' are not the best way to create a request ...

//Подготавливаем запрос для жанров var querygenre = 'INSERT INTO `genre_novel` (`novel_id`, `genre_id`) VALUES '; for (temp_genre in req.body.genre) { querygenre += '('+req.params.idnovel+', ?),'; } querygenre = querygenre.substring(0, querygenre.length - 1); //Получается INSERT INTO `genre_novel` (`novel_id`, `genre_id`) VALUES (1, ?), (2, ?) и т.д. pool.query(' DELETE FROM `genre_novel` WHERE novel_id = ?; '+querygenre+' ', [req.params.idnovel, req.body.genre] , function(err, rows, fields) { if (err) return next(err); 
  • I receive an array from the post request, from which: 1) You need to update the book (Description, titles, etc.) 2) And from another table you need to update the genres of this book. For point 2, the simplest thing to me was the following: delete all genres belonging to the book and insert the received post with the query, which I actually try to do. Perhaps there is a simpler way, but I don’t know about it. - enhaster

1 answer 1

In general, just use pool.escape.

     arrGenre.forEach (function (item, i, arrGenre) {        
         querygenre + = '(' + pool.escape (req.params.idnovel) + ',' + pool.escape (item) + '),';
       });