0

I'm currently trying to implement a simple MySQL Database into my App. It should add a new User OR update if this User Exists. I'm working with Node.js mysql.

My code is:

INSERT INTO User ? ON DUPLICATE KEY UPDATE cost=VALUES(cost),
city=VALUES(city), romantik=VALUES(romantik),
kultur=VALUES(kultur), abenteuer=VALUES(abenteuer), 
familie=VALUES(familie), citytrip=VALUES(citytrip), 
kreuzfahrt=VALUES(kreuzfahrt)

and the output code is:

'INSERT INTO User `userId` = 566160350174682, `cost` = 400,
`city` = \'Berlin\', `romantik` = false,
`kultur` = true, `abenteuer` = true, `familie` = false,
`citytrip` = true, `kreuzfahrt` = false ON DUPLICATE KEY
UPDATE cost=VALUES(cost), city=VALUES(city), kultur=VALUES(kultur),
abenteuer=VALUES(abenteuer), familie=VALUES(familie),
citytrip=VALUES(citytrip), kreuzfahrt=VALUES(kreuzfahrt)'

This should work as far as I know but it always returns this error:

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 \'userId = 566160350174682, cost = 400, city = \'Berlin\' at line 1

Can Somebody explain why this is happening and how I can solve this?

0

1 Answer 1

3

You have to use SET ..

Your query should be

INSERT INTO User SET `userId` = 566160350174682, `cost` = 400,
`city` = \'Berlin\', `romantik` = false, `kultur` = true, 
`abenteuer` = true, `familie` = false, `citytrip` = `kreuzfahrt` = false ON DUPLICATE KEY UPDATE cost=VALUES(cost), city=VALUES(city), kultur=VALUES(kultur),
abenteuer=VALUES(abenteuer), familie=VALUES(familie), citytrip=VALUES(citytrip), kreuzfahrt=VALUES(kreuzfahrt)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.