2

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
asked Nov 30, 2017 at 20:02
1
  • This question has been asked before Commented Nov 30, 2017 at 20:11

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.