A
A
alaskafx2021-09-06 15:38:11
MySQL
alaskafx, 2021-09-06 15:38:11

How to send object to mysql database via nodejs?

How can I send an object to the database?
When I execute this:

connection.query('INSERT INTO `users` SET winhist = ? WHERE uid = ?', [win, uid], function (error, results, fields) {
    if (error) throw error;
    console.log(results)
  });


- an error occurs:


code: 'ER_PARSE_ERROR',
errno: 1064,
sqlState: '42000',
sqlMessage: "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 'WHERE uid = 458035084 ' at line 1",
sql: 'INSERT INTO `users` SET winhist = \'{\\"name\\":\\"RANDOM\\",\\"price\\":105,\\"discount \\":5,\\"img\\":\\" https://i.imgur.com/F0hjmJ8.png\\",\\"maxLPrizes\\":4}\ ' WHERE uid = 458035084 '
}


- already tried to write like this :; ; - the same error appears. How to decide?
let win = JSON.parse(req.body.win)
let win = req.body.win


Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexandroppolus, 2021-09-06
@Alexandroppolus

Try replacing "INSERT INTO" with "UPDATE"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question