MySQL数据库不保存数据。特金特

2024-09-28 20:20:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我是编程界的新手,我正在尝试使用Tkinter创建一个web应用程序

现在我无法将数据插入MySQL;我试图将输入到Tkinter中创建的表单中的数据保存到MySQL数据库中,但我做不到。这不会给我带来任何错误。我已经在MySQL Workbench中创建了表,但是表单中输入的数据没有保存

我犯了什么错

我很感激你能给我的帮助

def pedir_fav():
    global pedir_favor
    pedir_favor = Toplevel(ventana_desplegable)
    pedir_favor.title("UNidos")
    pedir_favor.geometry("510x550")
    pedir_favor.resizable(False, False)
    pedir_favor.config(background="#213141")

    global favor
    global lugar
    global dinero
    global tiempo
    global agregar
    global favor_entry
    global lugar_entry
    global dinero_entry
    global tiempo_entry
    global agregar_entry

    favor = StringVar()
    lugar = StringVar()
    dinero = StringVar()
    tiempo = StringVar()
    agregar = StringVar()

    Label(pedir_favor, text="UNidos", font=("Cambria", 14), bg="dodgerblue3", fg="white", width="500", height="2").pack()
    Label(pedir_favor, text="Ingrese sus datos", bg="#213141", fg="white").pack()

    favor_label = Label(pedir_favor, text="¿Qué necesitas?", bg="#213141", fg="white").place(x=22, y=80)
    favor_entry = Entry(pedir_favor, textvariable=favor, width="35").place(x=22, y=110)

    lugar_label = Label(pedir_favor, text="¿En que lugar lo necesitas?", bg="#213141", fg="white").place(x=22, y=140)
    lugar_entry = Entry(pedir_favor, textvariable=lugar, width="35").place(x=22, y=170)

    dinero_label = Label(pedir_favor, text="¿Qué recompensa ofreces?", bg="#213141", fg="white").place(x=22, y=200)
    dinero_entry = Entry(pedir_favor, textvariable=dinero, width="35").place(x=22, y=230)

    tiempo_label = Label(pedir_favor, text="¿En cuanto tiempo lo esperas?", bg="#213141", fg="white").place(x=22, y=260)
    tiempo_entry = Entry(pedir_favor, textvariable=tiempo, width="35").place(x=22, y=290)

    agregar_label = Label(pedir_favor, text="¿Algo que agregar?", bg="#213141", fg="white").place(x=22, y=320)
    agregar_entry = Entry(pedir_favor, textvariable=agregar, width="35").place(x=22, y=350)

    Button(pedir_favor, text="Registrarse", width="30", height="2", command=registro_favores, bg="dodgerblue3", fg="white").place(x=22, y=385)
    #Button(pedir_favor, text="Volver al inicio", width="30", height="2", command=cierre, bg="dodgerblue3", fg="white").place(x=22, y=440)

def registro_favores():
    please = favor.get()
    place = lugar.get()
    money = dinero.get()
    time = tiempo.get()
    ad = agregar.get()
    print(please, "\t\n", place, "\t\n", money, "\t\n", time, "\t\n", ad, "\t\n")
    cnx = mysql.connector.connect(user='root',
                                  host='localhost',
                                  database='registro_unidos')
    cursor = cnx.cursor()
    
    query = "INSERT INTO `registro-favores` (please, lugar, agregar, money, tiempo) VALUES (%s, %s, %s, %s, %s)"   

    cursor.execute(query, (please, place, ad, money, time))

    cursor.close()

    cnx.close()

Tags: textplacewidthgloballabelbgentrywhite