0

I am trying to insert data in a specific row using MYSQL in PYTHON.

I've tried the following code :

sql = "INSERT INTO board (pages) VALUES (%s) WHERE (ASIN) = '" + asinList[x] + "'"
val = (a)
myCurser.execute(sql, val)

However, I got this error :

"

mysql.connector.errors.ProgrammingError: 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '%s) WHERE (ASIN) = 'B07KWSRMK1'' "

how to solve it?

ScaisEdge
134k10 gold badges98 silver badges111 bronze badges
asked May 18, 2019 at 9:35

1 Answer 1

1

INSERT does not support WHERE clause with VALUES.

If you really want add a new rows then you should use INSERT.

 sql = "INSERT INTO board (pages) VALUES (%s) '"

You may be looking to update an existing row. In this you should use UPDATE:

sql = "UPDATE board 
 SET pages = %s
 WHERE ASIN = %s"
Gordon Linoff
1.3m62 gold badges707 silver badges858 bronze badges
answered May 18, 2019 at 9:39
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.