0% found this document useful (0 votes)
10 views4 pages

Employee Management System in Python

This document contains a Python script for an Employee Management System that connects to a MySQL database. It includes functions to add, view, search, update, and delete employee records. The script also features a main menu for user interaction to perform these operations.

Uploaded by

tanishsahu008
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Employee Management System in Python

This document contains a Python script for an Employee Management System that connects to a MySQL database. It includes functions to add, view, search, update, and delete employee records. The script also features a main menu for user interaction to perform these operations.

Uploaded by

tanishsahu008
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PYTHON CODES

import [Link]

# Database Connection
con = [Link](
host="localhost",
user="root", # change if needed
password="your_password", # change this
database="employee_db"
)

cursor = [Link]()

# Add Employee
def add_employee():
emp_id = int(input("Enter Employee ID: "))
name = input("Enter Name: ")
dept = input("Enter Department: ")
salary = int(input("Enter Salary: "))
phone = input("Enter Phone Number: ")

sql = "INSERT INTO employee VALUES (%s, %s, %s, %s, %s)"
data = (emp_id, name, dept, salary, phone)

[Link](sql, data)
[Link]()
print("✅ Employee Added Successfully")

# View Employees
def view_employee():
[Link]("SELECT * FROM employee")
data = [Link]()

print("\n--- Employee Records ---")


for row in data:
print(row)

# Search Employee
def search_employee():
emp_id = int(input("Enter Employee ID to search: "))
[Link]("SELECT * FROM employee WHERE emp_id=%s", (emp_id,))
data = [Link]()

if data:
print("Employee Found:", data)
else:
print("❌ Employee Not Found")

# Update Employee
def update_employee():
emp_id = int(input("Enter Employee ID to update: "))
salary = int(input("Enter New Salary: "))

[Link]("UPDATE employee SET salary=%s WHERE emp_id=%s",


(salary, emp_id))
[Link]()
print("✅ Employee Updated Successfully")

# Delete Employee
def delete_employee():
emp_id = int(input("Enter Employee ID to delete: "))
[Link]("DELETE FROM employee WHERE emp_id=%s", (emp_id,))
[Link]()
print(" Employee Deleted Successfully")

# Main Menu
while True:
print("""
===== Employee Management System =====
1. Add Employee
2. View Employees
3. Search Employee
4. Update Employee
5. Delete Employee
6. Exit
""")

choice = int(input("Enter your choice: "))


if choice == 1:
add_employee()
elif choice == 2:
view_employee()
elif choice == 3:
search_employee()
elif choice == 4:
update_employee()
elif choice == 5:
delete_employee()
elif choice == 6:
print("Thank You 😊")
break
else:
print("❌ Invalid Choice")

You might also like