Как решить проблему записи данных в таблицу MySQL подключенную к графическому интерфейсу Tkinter?

from tkinter import *
import tkinter as tk
from tkinter import ttk
import mysql.connector as mysql


db = mysql.connect(host = 'localhost', user = 'root', password = 'ytroslav2006', database = 
'srudent_registration')
mycursor = db.cursor()

def Add(): 
    id = e1.get()
    name = e2.get()
    section = e3.get()

    sql = "INSERT INTO student (id_number, name, section), VALUES(%s, %s, %s)"
    value = (id, name, section)
    mycursor.execute(sql, value)
    db.commit()

root = Tk()
root.geometry("800x800")

Label(root, text = "Student Registration", font = ("Arial", 30, "bold")).grid(row = 0, column = 3)

#Label_1
id_number = Label(root, text = "id_number")
name = Label(root, text = "name")
section = Label(root, text = "section")

id_number.grid(row = 1, column = 2)
name.grid(row = 2, column = 2)
section.grid(row = 3, column = 3)

#Entry
e1 = Entry(root)
e2 = Entry(root)
e3 = Entry(root)

e1.grid(row = 1, column = 3)
e2.grid(row = 2, column = 3)
e3.grid(row = 3, column = 3)

#Button
Button(root, text = "Add", command = Add, height = 3, width = 10).place(x = 50, y = 400)
Button(root, text = "Edit", command = "", height = 3, width = 10).place(x = 150, y = 400)
Button(root, text = "Delete", command = "", height = 3, width = 10).place(x = 250, y = 400)
Button(root, text = "Show List", command = "", height = 3, width = 10).place(x = 350, y = 400)

#Список для записей студентов в базе данных
column1 = ('id_number', 'Name', 'Username')
listbox = ttk.Treeview(root, columns = column1, show = 'headings')

for col in column1:
    listbox.heading(col, text = col)
    listbox.grid(row = 1, column = 0, columnspan = 2)
    listbox.place(x = 9, y = 150)

root.mainloop()

После ввода данных в поля "id", "name", "section" и нажатия на кнопку "Add", в таблицу "клиент", при выполнении скрипта SQL, должна записаться введенная информация, но такого не происходит. Где ошибка?


Ответы (0 шт):