Hilde Schneider
Hilde Schneider

Reputation: 25

Updating column data using a variable

I have been trying to update my column data using a variable. Am I using the correct syntax?

I've tried looking for syntaxes but I still get the same error.

p1Score = 1
mycursor.execute("UPDATE test SET score = %s WHERE players = 'Player one'")
mydb.commit()
print(mycursor.rowcount, "record(s) affected")

I expect the score column of p1 to change into 1 but I get an error that says 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 players = 'Player One'' at line 1

Upvotes: 0

Views: 34

Answers (1)

Rajat Gaur
Rajat Gaur

Reputation: 39

You didn't set the value of %s. The correct query is

p1Score = (1)
mycursor.execute("UPDATE test SET score = %s WHERE players = 'Player one'",p1Score )
mydb.commit()
print(mycursor.rowcount, "record(s) affected")

Upvotes: 1

Related Questions