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!
CodePudding user response:
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
...
