from tkinter import *
from tkinter import messagebox
import mysql.connector
from tkinter import Button
def ok():
name = e1.get()
salary = e2.get()
dob = e3.get()
mysqldb = mysql.connector.connect(host="localhost", user="root", password="", database="sahil")
mycursor = mysqldb.cursor()
try:
sql = "INSERT INTO clients(ID,NAME,SALARY,DOB) VALUES(%s, %s, %s, %s)"
val = (name, salary, dob)
mycursor.execute(sql, val)
mysqldb.commit()
messagebox.showinfo("information", "record inserted succesfully..")
except Exception as e:
print(e)
mysqldb.rollback()
mysqldb.close()
root = Tk()
root.title("client data")
root.geometry("400x400")
global e1
global e2
global e3
Label(root, text="NAME").place(x=10, y=10)
Label(root, text="SALARY").place(x=10, y=40)
Label(root, text="DOB").place(x=10, y=80)
e1 = Entry(root)
e1.place(x=140, y=10)
e2 = Entry(root)
e2.place(x=140, y=40)
e3 = Entry(root)
e3.place(x=140, y=80)
Button(root, text="ADD", command="ok").place(x=10, y=120)
root.mainloop()
Question posted in PhpMyAdmin
The official documentation can be found here.
The official documentation can be found here.
2
Answers
it should be
command=ok
...rather thencommand="ok"
you dont show parts of your code, they would maybe interesting. but if you want to know how to use "Insert" with pythond and mysql here is one suggestion (this isn’t on your code because you give less informations, but you can try this)