So I was trying to do a registration panel in tkinter. I already did a login page, but I'm not so successful with a register page.
This is the code:
def register():
uname=username.get()
pw=password.get()
email=emil.get()
savequery = "INSERT INTO `userinfo`(uname, email, pw) VALUES (%s,%s,%s)"
cursor.execute(savequery, [(uname),(email),(pw)])
results = cursor.fetchall()
if results:
messagebox.showinfo("Nakami - Register","Sikeres regisztráció! Jelentkezz be!")
os.startfile("Nakami.pyw")
root.destroy()
else:
messagebox.showinfo("Nakami - Register","Hiba! (Lehet hogy az adatok már foglaltak)")
return False
Can someone help me out? Thanks!
Calling cursor.fetchall()
will get no record after executing INSERT
SQL statement. You need to use cursor.rowcount
to check whether record has been inserted or not. Also you need to call conn.commit()
(assume conn
is the MySQL connection object) to make the insertion effective.
savequery = 'INSERT INTO `userinfo` (uname, email, pw) VALUES (%s, %s, %s)'
cursor.execute(savequery, [uname, email, pw])
if cursor.rowcount > 0:
# insert successful
conn.commit() # commit the change to make the insertion effective
...
else:
# insert failed
...
The problem is, that it gives me no error at all. It just jumps to the else part immediatelly, without writing in any data into the MySQL table.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.