Part of my code calls up an edit window. In this window it pulls the information from the record you want to update based of the C_ID unique ID number. You enter the ID number in the box for either updating or deleted the record.
I have written the update code a few different ways, it has been a good long while since I worked with SQL and just started to write python a week ago, and for the life of me I can’t figure out the issue at hand. If you need to see more of the code I could post it. Right now every connects through a py script for connecting to DB so I don’t have to type it out, or copy past it all the time. The Cursor is in that code as well, reason for the cur, conn =
def update():
cur, conn = connection.get_connection()
record_id = delete_box.get()
cur.execute("""UPDATE car_exp SET
C_ID =:C_ID,
C_Date =:C_Date,
C_Payment =:C_Payment,
C_CAA =:C_CAA,
C_Maintenance =:C_Maintenance,
C_Insurance =:C_Insurance,
C_Gas =:C_Gas,
C_Addt_1 =:C_Addt_1,
C_Addt_2 =:C_Addt_2
WHERE C_ID = :C_ID""",
{
'C_ID': record_id,
'Date': C_Date_editor.get (),
'C_Payment': C_Payment_editor.get (),
'C_CAA': C_CAA_editor.get (),
'C_Maintenance': C_Maintenance_editor.get (),
'C_Gas': C_Gas_editor.get (),
'C_Addt_1': C_Addt_1_editor.get (),
'C_Addt_2': C_Addt_2_editor.get ()})
conn.commit()
conn.close()
I have tried this method as well for execute, same error.
("UPDATE car_exp SET C_ID=%s,C_Date=%s,C_Payment=%s,C_CAA=%s,C_Maintenance=%s,C_Insurance=%s,C_Gas=%s,C_Addt_1=%s,C_Addt_2=%s, WHERE C_ID = :C_ID",{
'C_ID': C_ID_editor.get(),
'C_Date': C_Date_editor.get (),
'C_Payment': C_Payment_editor.get (),
'C_CAA': C_CAA_editor.get (),
'C_Maintenance': C_Maintenance_editor.get (),
'C_Gas': C_Gas_editor.get (),
'C_Addt_1': C_Addt_1_editor.get (),
'C_Addt_2': C_Addt_2_editor.get ()})
When I go to run this part of the code I get the error:
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 ‘:C_ID,
C_Date =:C_Date,
C_Paym’ at line 2
user3166928 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.