โ† Projects
PHP + MySQL Project 05

Employee Management System

Build a practical employee management system using PHP, MySQL, HTML and CSS. You will learn how to store, display, update and delete employee records.

๐ŸŽฏ What You Will Build

A complete CRUD-based Employee Management System.

โž• Add
๐Ÿ‘ View
โœ๏ธ Edit
๐Ÿ—‘ Delete
๐Ÿ” Search

๐Ÿ›  Technologies Used

๐Ÿ“ Project Structure

employee-management/
โ”‚
โ”œโ”€โ”€ tutorial.php
โ”œโ”€โ”€ index.php
โ”œโ”€โ”€ add.php
โ”œโ”€โ”€ edit.php
โ”œโ”€โ”€ delete.php
โ”œโ”€โ”€ style.css
โ””โ”€โ”€ database.sql
        

๐Ÿ—„๏ธ Step 1 โ€” Create Database

Open phpMyAdmin and use the existing database:

aifa_php_lab

MySQL is running on port 3307.

๐Ÿ—ƒ๏ธ Step 2 โ€” Create Employees Table

Run the following SQL query inside aifa_php_lab.

CREATE TABLE IF NOT EXISTS employees (

    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,

    full_name VARCHAR(100) NOT NULL,

    email VARCHAR(150) NOT NULL,

    phone VARCHAR(20) NOT NULL,

    department VARCHAR(100) NOT NULL,

    designation VARCHAR(100) NOT NULL,

    salary DECIMAL(10,2) NOT NULL,

    city VARCHAR(100) NOT NULL,

    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

);
        

๐Ÿ”Œ Step 3 โ€” Connect PHP with MySQL

$host = "127.0.0.1";
$user = "root";
$password = "";
$database = "aifa_php_lab";
$port = 3307;

$conn = new mysqli(
    $host,
    $user,
    $password,
    $database,
    $port
);
        

๐Ÿ”„ Step 4 โ€” Understand CRUD

1

Create

Add a new employee using an HTML form and an INSERT query.

2

Read

Fetch employee records from MySQL using SELECT and display them.

3

Update

Modify employee information using an UPDATE query.

4

Delete

Remove an employee record using a DELETE query.

โž• Step 5 โ€” Add Employee

The form will collect:

The data will be inserted using a prepared statement.

๐Ÿ‘๏ธ Step 6 โ€” View Employees

SELECT *
FROM employees
ORDER BY id DESC
        

Employee records will be displayed in a responsive table.

โœ๏ธ Step 7 โ€” Edit Employee

The employee ID will identify the record that needs to be updated.

UPDATE employees
SET
    full_name = ?,
    email = ?,
    phone = ?,
    department = ?,
    designation = ?,
    salary = ?,
    city = ?
WHERE id = ?
        

๐Ÿ—‘๏ธ Step 8 โ€” Delete Employee

DELETE FROM employees
WHERE id = ?
        

๐Ÿ” Security Rules

๐Ÿงช Practice Tasks

  1. Add five employees.
  2. Edit an employee's designation.
  3. Change an employee's salary.
  4. Delete an employee.
  5. Search employees by department.

๐Ÿš€ Ready to Build?

Complete the tutorial and then run the working Employee Management System.

Run Complete Project โ†’