I am a beginner in python. when i insert the record into the database. records are not added. I have a two columns in the database id,name. id set in mysql auto increment.
from tkinter import *
import mysql.connector # Importing Connector package
def Ok():
result = e1.get()
mysqldb=mysql.connector.connect(host="localhost",user="root",password="",database="empdb")#established connection between your database
mycursor=mysqldb.cursor()
try:
mycursor.execute("insert into records values(%s)", (result,))
mysqldb.commit()
print('Record inserted successfully...')
except Exception as e:
print(e)
mysqldb.rollback()
mysqldb.close()
raise Exception("Sorry, no numbers below zero")
root = Tk()
root.title("Employee Salary Calculation System")
root.geometry("300x400")
global e1
Label(root, text="Employee Name").place(x=10, y=10)
e1 = Entry(root)
e1.place(x=100, y=10)
Button(root, text="Cal", command=Ok ,height = 1, width = 3).place(x=10, y=150)
root.mainloop()
Error displayed
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\kobinath\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/kobinath/PycharmProjects/pythonProject4/employee.py", line 20, in Ok
raise Exception("Sorry, no numbers below zero")
Exception: Sorry, no numbers below zero
I got the error above.