In my python code, I want to update the table value as per the user input so i need to pass the dynamic value in the query but i am not able to get any result. Can you suggest me way?
Below is my code:`
import mysql.connector
zone = # Dynamic value
rate = # Dynamic value
conn=mysql.connector.connect(user='root',password='1234',host='localhost',database='demo')
mycursor=conn.cursor()
mycursor.execute("UPDATE interest_rate SET interest=(rate,) where Bank_Name=%s",(zone,))
conn.commit()
`
How to pass the rate in the UPDATE query, I am able to pass the zone variable in the query. Can you help me to pass the rate variable?
I am using python 3.4 and MySQL as the database.
Mureinik
316k54 gold badges403 silver badges406 bronze badges
-
This question has been asked beforeZooby– Zooby2017年11月30日 20:11:11 +00:00Commented Nov 30, 2017 at 20:11
1 Answer 1
You need to use placeholders for all the values and provide all the values as the second argument, as a tuple:
mycursor.execute("UPDATE interest_rate SET interest=%s where Bank_Name=%s", (rate, zone))
answered Nov 30, 2017 at 20:07
Mureinik
316k54 gold badges403 silver badges406 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default