0

I'm using mysql with python, I got an error when using a bind varialbe. Actually I don't know how to use a bind variable. Please help me with my problem.

Here is my code:

iouNo=textiv1.get()
    cursor.execute("UPDATE iou_table SET IOU_status=4 WHERE IOU_No= :iouNo",{'iouNo':iouNo})
    mydb.commit()

This is the error I got

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 ':'iouNo'' at line 1

I want to use the iouNo variable inside the SQL query... How can I do it?

1

1 Answer 1

0

You can read up on that iin the manual from MySQL.

%s is used as place holde.

If you only have one parameter or variable you still have tpo use a 2 dimensional tuple,

iouNo=textiv1.get()
cursor.execute("UPDATE iou_table SET IOU_status=4 WHERE IOU_No= %s;",(iouNo,))
mydb.commit()
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.