I'm new to Python and especially to SQL.
My goal is:
- A user should enter which phone number he wants to change
- Then the user should be able to enter the new phone number
- This change should then be stored in my MySQL database
As I know the syntax for an update is like this:
sql = "UPDATE table SET fieldname = value" "WHERE fieldname = value"
But if I try to use the code with two variables from an input, it doesn't work:
input_change = input("Write the number to change: ")
input_new = input("Write the new number: ")
sql = "UPDATE table SET telefonnummer = ?" "WHERE telefonnummer = ?"
cursor.execute(sql, (input_change, input_new))
connection.commit()
Does somebody have an idea how I can fix this? Or where can I find a good description about using variables in SQL statements?
Many thanks for the answers.
sql = "UPDATE table SET telefonnummer = ?" "WHERE telefonnummer = ?"tosql ='''UPDATE table SET telefonnummer = ? WHERE telefonnummer = ?'''