1

I am trying to update three columns in my table with data by using Python variables, but I have ran into an issue which I don't seem to understand.

I have done some amendments but still run into issues, can anyone see what I am doing wrong?

My table:

Columns id code url val1 val2 val3
Data 1 A2941 url.com NULL NULL NULL

My query:

cursor.execute("UPDATE mytable SET val1=%s", (myVar))

Error message:

mysql.connector.errors.ProgrammingError: 1064 (42000): 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 '%s' at line 1
asked Mar 28, 2020 at 18:48

1 Answer 1

1

execute takes a tuple as its second argument. (myVar) is just the myVar variable surrounded in parenthesis. To create a tuple that contains only myVar, you need to add a comma:

cursor.execute("UPDATE mytable SET val1=%s", (myVar,))
# Here --------------------------------------------^
answered Mar 28, 2020 at 18:52
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.