0

Okay, I got a sql query here, and I want to put a dynamic value in userID but when I put this query with another query, It seems like the whole sql query doesn't work. I think It has some problem with template string but no clue why It's not working.

query that I'm trying to use

insert into CREDIT values (uuid(), userID, null, now(), now(), 3.00, 'C', now(), now(), null, null);

actual js code

let query = "UPDATE USER SET STATUS = 'C' WHERE CONFIRM_KEY = " + ${mysql.escape(req.params.id)}
   query += `INSERT INTO CREDIT VALUES (uuid(), ${req.params.id}, null, now(), now(), 3.00, 'C', now(), now(), null, null)`

let result = await pool.query(query)

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 \'INSERT INTO CREDIT VALUES (uuid(), \'66915b91-f9f7-11e7-8ffe-8785394e9837\', null,\' at line 1' }
1
  • @thisDonkey like WHERE CONFIRM_KEY = " + "'" + {mysql.escape(req.params.id)} + "'" ? Commented Jan 15, 2018 at 13:34

1 Answer 1

2

It looks like you are trying to combine an update and an insert in a single query. That's not possible. Execute each as a separate query.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.