PHP project Β· MySQL Β· source code

Event Management System in PHP & MySQL (Source Code)

Build an event management system project in PHP and MySQL: three tables, bcrypt login, event listing, registration and unique ticket codes. Every file has a copy button.

event_listing.php
// event_listing.php
$sql = "SELECT * FROM events
        WHERE date >= NOW()
        ORDER BY date ASC";

while ($row = mysqli_fetch_assoc($result)) {
    echo htmlspecialchars($row['name']);
}

What is an event management system project in PHP?

A web app where administrators publish events and attendees register and receive a ticket. Behind it sit a MySQL database, PHP sessions and a few form handlers.

πŸŽͺ

What you will build

Login, event creation, event listing, registration and ticket codes in plain PHP with mysqli, ready to extend with a photo gallery and live chat.

🐘

Why PHP?

PHP runs on any shared host and XAMPP or Laragon, and mysqli talks to MySQL natively. Move to a PHP MVC structure later without rewriting the database.

🧰

Requirements

PHP 8+, MySQL or MariaDB, phpMyAdmin, and a local server such as XAMPP or Laragon.

πŸ“

Files you will create

schema.sql, auth.php, events.php and register_event.php, about 100 lines of PHP in total.

Event management system project features

Eight modules, from login to live chat. The first four are built below.

πŸ”

User registration & login

Sign-up and login with password_hash() and PHP sessions.

πŸ—“οΈ

Event creation

Admin form that saves name, description, date and location to the events table.

πŸ”Ž

Event listing & search

Shows upcoming events only (date >= NOW()), filterable by date, location and category.

🎟️

Event registration

One click registers the logged-in user in the registrations table.

🧾

Ticket generation

A unique random ticket code per registration, printable or downloadable.

⏰

Event reminders

A cron job emails registered users 24 hours before the event.

πŸ–ΌοΈ

PHP photo gallery

Upload event photos and show them in a responsive gallery.

πŸ’¬

Real-time chat

Live attendee chat over a Ratchet WebSocket server.

Event management system source code, step by step

Click Copy on each file. The code assumes a mysqli connection stored in $connection.

1

Step 1: Create the MySQL database (events, users, registrations)

Three tables store events, attendees and ticket registrations, linked by foreign keys.

schema.sql
CREATE TABLE events (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    description TEXT,
    date DATETIME,
    location VARCHAR(255)
);

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(255) NOT NULL,
    email VARCHAR(255) NOT NULL,
    password VARCHAR(255) NOT NULL
);

CREATE TABLE registrations (
    id INT AUTO_INCREMENT PRIMARY KEY,
    event_id INT NOT NULL,
    user_id INT NOT NULL,
    ticket_code VARCHAR(255) NOT NULL,
    FOREIGN KEY (event_id) REFERENCES events(id),
    FOREIGN KEY (user_id) REFERENCES users(id)
);
2

Step 2: Secure registration and login with password_hash()

Passwords are hashed with bcrypt, queries use mysqli prepared statements, and the session ID is regenerated on login.

auth.php
<?php
session_start();

// User Registration
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['register_user'])) {
    $username = $_POST['username'];
    $email    = $_POST['email'];
    $password = password_hash($_POST['password'], PASSWORD_BCRYPT);

    $stmt = mysqli_prepare($connection,
        "INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
    mysqli_stmt_bind_param($stmt, "sss", $username, $email, $password);

    if (mysqli_stmt_execute($stmt)) {
        header('Location: login.php');
        exit();
    }
    echo "User registration failed. Please try again.";
}

// User Login
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['login'])) {
    $stmt = mysqli_prepare($connection,
        "SELECT id, password FROM users WHERE username = ?");
    mysqli_stmt_bind_param($stmt, "s", $_POST['username']);
    mysqli_stmt_execute($stmt);
    $user = mysqli_fetch_assoc(mysqli_stmt_get_result($stmt));

    if ($user && password_verify($_POST['password'], $user['password'])) {
        session_regenerate_id(true);
        $_SESSION['user_id'] = $user['id'];
        header('Location: dashboard.php');
        exit();
    }
    echo "Invalid username or password.";
}
3

Step 3: Create and list upcoming events

Administrators insert events, and the listing query returns only future events ordered by date.

events.php
<?php
// Event Creation
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_event'])) {
    $stmt = mysqli_prepare($connection,
        "INSERT INTO events (name, date, location, description) VALUES (?, ?, ?, ?)");
    mysqli_stmt_bind_param($stmt, "ssss",
        $_POST['event_name'], $_POST['event_date'],
        $_POST['event_location'], $_POST['event_description']);

    if (mysqli_stmt_execute($stmt)) {
        header('Location: event_listing.php');
        exit();
    }
    echo "Event creation failed.";
}

// Event Listing
$sql = "SELECT * FROM events WHERE date >= NOW() ORDER BY date ASC";
$result = mysqli_query($connection, $sql);
while ($row = mysqli_fetch_assoc($result)) {
    echo "Event Name: " . htmlspecialchars($row['name']) . "<br>";
    echo "Date: " . htmlspecialchars($row['date']) . "<br>";
    echo "Location: " . htmlspecialchars($row['location']) . "<br><br>";
}
4

Step 4: Register for an event and generate a unique ticket code

The user ID comes from the session, and random_bytes() produces a ticket code that cannot be guessed.

register_event.php
<?php
function generateTicketCode() {
    return strtoupper(bin2hex(random_bytes(6)));
}

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['register_event'])) {
    $eventId    = (int) $_POST['event_id'];
    $userId     = $_SESSION['user_id'];
    $ticketCode = generateTicketCode();

    $stmt = mysqli_prepare($connection,
        "INSERT INTO registrations (event_id, user_id, ticket_code) VALUES (?, ?, ?)");
    mysqli_stmt_bind_param($stmt, "iis", $eventId, $userId, $ticketCode);

    if (mysqli_stmt_execute($stmt)) {
        echo "Registration successful! Your ticket code is: $ticketCode";
    } else {
        echo "Registration failed. Please try again.";
    }
}
5

Step 5: Add real-time chat (Ratchet) and a photo gallery

Run a Ratchet WebSocket server (composer require cboden/ratchet) for live attendee chat, and store event photos in an uploads/ folder with their paths saved in the database. Both features build on the users and events tables you already created.

Security note: these examples use prepared statements, hashed passwords and escaped output. Always do the same in your own projects, and add admin checks before letting users create events.

Event management system project in PHP: GitHub, free download and PDF docs

How to pick a project with source code that is safe to reuse.

πŸ™

GitHub repositories

Search β€œevent management system php mysql”, sort by recently updated, and check the licence and last commit before reusing code.

🎁

Free source code downloads

Most ZIPs ship a .sql dump: import it in phpMyAdmin, then point config.php at your database.

πŸ“„

Project documentation PDF

Good docs include an ER diagram, a module list (admin, user, events, tickets) and install steps.

πŸ—„οΈ

PHP and MySQL examples

A complete example has a .sql file, a config file, a login page and an admin dashboard.

🧱

PHP MVC from scratch

Rebuild it with Event, User and Registration models plus controllers and views to scale.

🀝

Contribute on GitHub

Add email reminders or QR tickets, then send a pull request to the project.

Conclusion

Import the schema, run Step 2.

Create the database in phpMyAdmin, paste schema.sql, then add reminders, QR tickets or chat. Happy coding!

More PHP projects β†—

Frequently asked questions

How do I build an event management system in PHP and MySQL?

Create three tables (events, users, registrations), add registration and login with password_hash(), build the event creation and listing pages, then generate a unique ticket code for every registration. The five steps on this page contain all the PHP source code.

Which database tables does an event management system need?

At minimum three: events (name, description, date, location), users (username, email, hashed password) and registrations (event_id, user_id, ticket_code), linked with foreign keys.

How do I generate a unique ticket code in PHP?

Use random_bytes() with bin2hex(), for example strtoupper(bin2hex(random_bytes(6))), and store it in the registrations table. Add a UNIQUE index on ticket_code so duplicates are impossible.

How do I prevent SQL injection in a PHP event management system?

Use mysqli prepared statements with bound parameters instead of placing $_POST values inside the query, hash passwords with password_hash(), and escape output with htmlspecialchars().

Where can I download event management system project in PHP source code?

Copy the code on this page, or search GitHub for β€œevent management system php mysql”. Before reusing a project, check its licence, its last commit date and whether it uses prepared statements.

Can I contribute to event management system projects on GitHub?

Yes. Fork an open-source repository, fix a bug or add a feature such as email reminders or QR tickets, then open a pull request.

How do I add real-time chat to a PHP event system?

PHP cannot push messages to browsers on its own, so run a WebSocket server such as Ratchet next to your site and connect to it with JavaScript on the event page.

Scroll to Top