PHP + MYSQL PROJECT

Student Registration System

Learn how to build a student registration system using HTML, CSS, PHP and MySQL.

What Are We Building?

We are going to create a student registration form. A student will enter personal and course information, and PHP will store the information inside MySQL.


This project teaches an important real-world concept: collecting data from a form and storing it safely in a database.

What You Will Learn

HTML Create the registration form.
PHP Receive and validate submitted data.
MySQL Store student information.

Project Requirements

XAMPP installed
Apache running
MySQL running
phpMyAdmin
Basic PHP knowledge

Step 1 — Create the Project Folder

Create a folder named:

student-registration

Inside it create:

student-registration/
│
├── tutorial.php
├── index.php
├── register.php
└── style.css

Step 2 — Create the Database Table

We will use the existing database:

aifa_php_lab

Inside it create a table named:

students

Run this SQL in phpMyAdmin after selecting aifa_php_lab:

CREATE TABLE IF NOT EXISTS students (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    full_name VARCHAR(100) NOT NULL,
    email VARCHAR(150) NOT NULL,
    phone VARCHAR(20) NOT NULL,
    dob DATE NOT NULL,
    gender VARCHAR(20) NOT NULL,
    course VARCHAR(100) NOT NULL,
    address TEXT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Step 3 — Create the Registration Form

Open index.php. The form will contain:

Full Name
Email
Phone
Date of Birth
Gender
Course
Address

The form sends data to register.php using POST.

<form action="register.php" method="POST">

Step 4 — Receive Data Using PHP

The register.php file receives form data through the PHP $_POST superglobal.

$name = trim($_POST['full_name'] ?? '');

$email = trim($_POST['email'] ?? '');

$phone = trim($_POST['phone'] ?? '');

$dob = trim($_POST['dob'] ?? '');

$gender = trim($_POST['gender'] ?? '');

$course = trim($_POST['course'] ?? '');

$address = trim($_POST['address'] ?? '');

The trim() function removes unnecessary spaces.

Step 5 — Validate Student Data

Before inserting data into MySQL, we must validate the information.

if (
    $name === '' ||
    $email === '' ||
    $phone === '' ||
    $dob === '' ||
    $gender === '' ||
    $course === '' ||
    $address === ''
) {
    // Show validation error
}

For email validation we can use:

if (!filter_var(
    $email,
    FILTER_VALIDATE_EMAIL
)) {
    // Invalid email
}

Step 6 — Connect PHP With MySQL

Our XAMPP MySQL server uses port 3307.

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

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

Step 7 — Insert Student Data

We use a prepared statement instead of directly putting user input inside the SQL query.

$sql = "
    INSERT INTO students
    (
        full_name,
        email,
        phone,
        dob,
        gender,
        course,
        address
    )
    VALUES (?, ?, ?, ?, ?, ?, ?)
";

$stmt = $conn->prepare($sql);

$stmt->bind_param(
    "sssssss",
    $name,
    $email,
    $phone,
    $dob,
    $gender,
    $course,
    $address
);

$stmt->execute();

The seven s characters represent seven string values.

Step 8 — Understand the Complete Flow

Student
→
HTML Form
→
register.php
→
Validation
→
MySQL

Important Rules

Always validate form data.
Use POST for registration forms.
Use prepared statements.
Never trust user input.
Keep database credentials secure.

Practice Questions

Add a father's or mother's name field.
Add a student ID field.
Add a qualification field.
Add a state and city field.
Create an admin page to display registered students.

Ready to See the Complete Project?

You have learned how the registration system works. Now open the working project.

🚀 Run Complete Project