I am trying to take data from entry fields and save it in the database. I have mentioned 6 columns in my SQL query but I have one more column in database which is ID and it is auto incremented. When I run this script I have no error but also no data gets inserted into the db rather than ID which is auto incremented. Here is my code:
window=tkinter.Tk()
# Set the window title
window.title("Princedeep Singh")
window.geometry("500x400")
current_row = 0
# Set the current row to zero
refdate_label = Label(window, text="Enter value for date: ")
refdate_label.grid(row=current_row, column=0)
refdate_text = StringVar()
refdate_entry = Entry(window, textvariable=refdate_text)
refdate_entry.grid(row=current_row, column=1)
current_row += 1
# geogeo field
geo_t_label = Label(window ,text="Enter value for geo:")
geo_t_label.grid(row=current_row, column=0)
geo_t_text = StringVar()
geo_t_entry = Entry(window, textvariable=geo_t_text)
geo_t_entry.grid(row=current_row, column=1)
current_row += 1
# commod field
commod_label = Label(window, text="Enter value for commod:")
commod_label.grid(row=current_row, column=0)
commod_text = StringVar()
commod_entry = Entry(window, textvariable=commod_text)
commod_entry.grid(row=current_row, column=1)
current_row += 1
# vector
vector_label = Label(window, text="Enter value for vector:")
vector_label.grid(row=current_row, column=0)
vector_text = StringVar()
vector_entry = Entry(window, textvariable=vector_text)
vector_entry.grid(row=current_row, column=1)
current_row += 1
# commod field
coordinate_label = Label(window, text="Enter value for coordinate:")
coordinate_label.grid(row=current_row, column=0)
coordinate_text = StringVar()
coordinate_entry = Entry(window, textvariable=coordinate_text)
print(coordinate_text)
coordinate_entry.grid(row=current_row, column=1)
current_row += 1
value_label = Label(window, text="Enter value :")
value_label.grid(row=current_row, column=0)
value_text = StringVar()
value_entry = Entry(window, textvariable=value_text)
value_entry.grid(row=current_row, column=1)
current_row += 1
conn = mysql.connector.connect(host='localhost', db='postgres', user='root',
password='root')
cur = conn.cursor()
submit = Button(window, text='submit', command=cur.execute('INSERT INTO
record(refdate,geo,commod,vector,coordinate,value) VALUES (%s, %s,
%s, %s, %s,%s)',
(refdate_text.get(),geo_t_text.get(),commod_text.get()
,vector_text.get(),str(coordinate_text.get()),value_text.get() )))
submit.grid(row=current_row+1, column=4)
conn.commit()
window.mainloop()