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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Does this answer your question? [How can I insert data into a MySQL database?](https://stackoverflow.com/questions/5687718/how-can-i-insert-data-into-a-mysql-database) – ktzr Feb 14 '21 at 17:13

1 Answers1

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()
nbk
  • 45,398
  • 8
  • 30
  • 47