python

Python Gui Last Insert ID Python Mysql

This tutorial will teach you how to get the Last Inserted id in python mysql. i will teach step by step.it will help you to make a inventory system.

from tkinter import *
from tkinter import messagebox
import mysql.connector

def Ok():
    empname = e2.get()
    phone = e3.get()
    salary = e4.get()

    mysqldb=mysql.connector.connect(host="localhost",user="root",password="",database="payrollpy")
    mycursor=mysqldb.cursor()

    try:
       sql = "INSERT INTO records (id,empname,phone,salary) VALUES (%s, %s, %s, %s)"
       val = ("",empname,phone,salary)
       mycursor.execute(sql, val)
       mysqldb.commit()

       lastid = mycursor.lastrowid

       messagebox.showinfo("information", "Record inserted successfully...")
       e1.delete(0, END)
       e1.insert(END, lastid)

       e2.delete(0, END)
       e3.delete(0, END)
       e4.delete(0, END)
       e2.focus_set()

    except Exception as e:

       print(e)
       mysqldb.rollback()
       mysqldb.close()

root = Tk()
root.title("Employee Registation")
root.geometry("300x500")
global e1
global e2
global e3
global e4
Label(root, text="Employee ID").place(x=10, y=10)
Label(root, text="Employee Name").place(x=10, y=40)
Label(root, text="phone").place(x=10, y=70)
Label(root, text="Salary").place(x=10, y=100)

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=70)

e4 = Entry(root)
e4.place(x=140, y=100)

Button(root, text="Add", command=Ok ,height = 3, width = 13).place(x=10, y=140)

root.mainloop()


i have attached the video link below. which will do this tutorials step by step.

admin

Recent Posts

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 weeks ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

1 month ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

1 month ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

1 month ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

2 months ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

2 months ago