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

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 --------------------------------------------^
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.