๐ฏ What You Will Build
A complete CRUD-based Employee Management System.
๐ Technologies Used
- HTML5
- CSS3
- PHP 8+
- MySQL
- Prepared Statements
- XAMPP
๐ 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:
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
Create
Add a new employee using an HTML form and an INSERT query.
Read
Fetch employee records from MySQL using SELECT and display them.
Update
Modify employee information using an UPDATE query.
Delete
Remove an employee record using a DELETE query.
โ Step 5 โ Add Employee
The form will collect:
- Full Name
- Phone
- Department
- Designation
- Salary
- City
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
- Use prepared statements for database queries.
- Validate all form fields.
- Validate email addresses.
- Validate salary as a numeric value.
- Escape displayed database data.
๐งช Practice Tasks
- Add five employees.
- Edit an employee's designation.
- Change an employee's salary.
- Delete an employee.
- Search employees by department.
๐ Ready to Build?
Complete the tutorial and then run the working Employee Management System.
Run Complete Project โ