๐ฏ What You Will Build
This project is a complete CRUD-based Student Management System.
๐ Technologies Used
- HTML5
- CSS3
- PHP 8+
- MySQL
- Prepared Statements
- XAMPP
๐ Project Structure
student-management/
โ
โโโ tutorial.php
โโโ index.php
โโโ add.php
โโโ edit.php
โโโ delete.php
โโโ style.css
โโโ database.sql
๐๏ธ Step 1 โ Create Database
Open phpMyAdmin and create a database named:
Your MySQL server is running on port 3307.
๐๏ธ Step 2 โ Create Students Table
Run this SQL query inside the aifa_php_lab database.
CREATE TABLE IF NOT EXISTS student_records (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
full_name VARCHAR(100) NOT NULL,
email VARCHAR(150) NOT NULL,
phone VARCHAR(20) NOT NULL,
course VARCHAR(100) NOT NULL,
city VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
๐ Step 3 โ Database Connection
PHP connects to MySQL using the
mysqli extension.
$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 student into the database using an HTML form and an INSERT query.
Read
Retrieve student records using a SELECT query and display them inside a table.
Update
Edit existing student information using an UPDATE query.
Delete
Remove a student record using a DELETE query.
โ Step 5 โ Insert Student
The Add Student form sends information through POST.
INSERT INTO student_records
(full_name, email, phone, course, city)
VALUES (?, ?, ?, ?, ?)
We will use prepared statements to safely insert the data.
๐ Step 6 โ Display Students
SELECT *
FROM student_records
ORDER BY id DESC
PHP will fetch the database records and display them inside a responsive table.
โ๏ธ Step 7 โ Update Student
First we select the student using the ID. Then the existing information is displayed inside the edit form.
UPDATE student_records
SET
full_name = ?,
email = ?,
phone = ?,
course = ?,
city = ?
WHERE id = ?
๐๏ธ Step 8 โ Delete Student
DELETE FROM student_records
WHERE id = ?
The student's ID identifies the exact record that should be removed.
๐ Security Rules
- Always use prepared statements.
- Never trust raw POST data.
- Validate email and required fields.
- Escape output using htmlspecialchars().
- Use POST for database-changing actions.
๐งช Practice Tasks
- Add five students.
- Edit one student's course.
- Delete one student.
- Search for a student by name.
- Add a new field called gender.
๐ Ready to Build?
After understanding the tutorial, open the complete working project.
Run Complete Project โ