I'm trying to take data from the user and insert it in to my database. Everything works fine until I clicked on 'Save' button. Then I get those erros:
Exception in Tkinter callback Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/init.py", line 1705, in call return self.func(*args) File "/Users/alidemirkazik/PycharmProjects/GUI_Test/GUI_Test.py", line 51, in add_customer mycursor.execute(sql, val) File "/Users/alidemirkazik/PycharmProjects/GUI_Test/venv/lib/python3.7/site-packages/mysql/connector/cursor.py", line 551, in execute self._handle_result(self._connection.cmd_query(stmt)) File "/Users/alidemirkazik/PycharmProjects/GUI_Test/venv/lib/python3.7/site-packages/mysql/connector/connection.py", line 490, in cmd_query result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query)) File "/Users/alidemirkazik/PycharmProjects/GUI_Test/venv/lib/python3.7/site-packages/mysql/connector/connection.py", line 395, in _handle_result raise errors.get_exception(packet) mysql.connector.errors.DatabaseError: 1366 (HY000): Incorrect integer value: '' for column 'ID' at row 1
Appreciate if anyone can help me with it. Thanks!
r = Tk()
r.title('Adding New Customer')
r.geometry("175x62")
def quit():
r.destroy()
def contact():
contact_window = Toplevel(r)
Label(contact_window, text='ID').grid(row=0)
Label(contact_window, text='Name').grid(row=1)
Label(contact_window, text='Address').grid(row=2)
Label(contact_window, text='Country').grid(row=3)
Label(contact_window, text='Age').grid(row=4)
input1 = Entry(contact_window)
input2 = Entry(contact_window)
input3 = Entry(contact_window)
input4 = Entry(contact_window)
input5 = Entry(contact_window)
input1.grid(row=0, column=1)
input2.grid(row=1, column=1)
input3.grid(row=2, column=1)
input4.grid(row=3, column=1)
input5.grid(row=4, column=1)
first_id = input1.get()
first_name = input2.get()
first_address = input3.get()
first_country = input4.get()
first_age = input5.get()
def add_customer():
mycursor = mydb.cursor()
sql = "INSERT INTO customers (ID, Name, Address, Country, Age) VALUES (%s, %s, %s, %s, %s)"
val = (first_id, first_name, first_address, first_country, first_age)
mycursor.execute(sql, val)
mydb.commit()
button3 = Button(contact_window, text="Save", command=add_customer)
button3.grid(row=5, column=1)
button1 = Button(r, text="Contact", command=contact).pack(fill=X, ipady=5)
button2 = Button(r, text="Exit", command=quit).pack(fill=X, ipady=5)
r.mainloop()