Hello!
I am trying to update a MySQL table using a Python code but I am having some problems. I define the connection and the cursor in the Ornithobase (wx.Frame)class in the OnLof function as

self.db= MySQLdb.connect(host='localhost', user=self.Username , passwd=self.pwd, db='Ornithobase')
self.cursor = self.db.cursor()

Then, in the same class but in another function, I try to update a MySQL table with this statement

if dlg.ShowModal() == wx.ID_OK:
    print 'Updating'
    sql = 'UPDATE Users SET Name = %s, FamilyName = %s, eMail = %s WHERE Username = %s'
    self.cursor.execute(sql, (Name, FamilyName, eMail, CurrentUser))
    self.db.commit()
    print 'Done'
    print Name
    print FamilyName
    print eMail
    print CurrentUser

The printing statements here were just to know whether the if statement was working and that the variable values were properly retrieved in the previous code. However, when I run it it neither updates the table nor it prints any error. Can anyone note if there is any mistake in the code?
Cheers!

Dani

Recommended Answers

All 5 Replies

Did you check what value dlg.showmodal() has before if?

This may seem quite naive, but, how can I check it?

Dani

response=dlg.ShowModal()
print response
print wx.ID_OK
print response==wx.ID_OK

Here's the output:

response=dlg.ShowModal()
print response
5100
print wx.ID_OK
5100
print response==wx.ID_OK
True

If you do not get 'Updating', if not, you must not reach the if even, but problem is before the code you posted.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.