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
1 Answer 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
Mureinik
316k54 gold badges404 silver badges406 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default