How to develop Projects(EMS) Using PHP and Mysql Part 12

Rashmi Mishra
0

 

How to develop Projects(EMS)

 Using PHP and Mysql 

Part 12


MODULE 4:

User Panel – Event Registration and Booking Management

🎯 Purpose:
Allow users to browse available events, register/book events, and manage their own bookings.

💡 Functionalities:

  • View list of available events
  • View event details (date, time, description, location, price)
  • Register/Book for an event
  • View their booking history
  • Cancel their own bookings (if allowed)
  • Download booking confirmation (PDF or simple receipt)

📁 Files Structure:

/user/

├── events_list.php           # Show list of available events

├── event_details.php         # View details of a single event

├── book_event.php            # Book or register for an event

├── my_bookings.php           # View user's bookings

├── cancel_booking.php        # Cancel a booking


Why this makes sense as the next step:

  • Admin management is done — now the system should let real users interact.
  • Balances your project — both backend (admin) and frontend (user) workflows.
  • It’s an essential flow: Events don’t just exist — users book them!

Code Details:

Use your table name , table names may vary.

💻 1 events_list.php — Show list of available events

<?php

session_start();

include('../db_connect.php');  // your database connection 

$query = "SELECT * FROM events_table ORDER BY date ASC";

$result = mysqli_query($conn, $query);

?> 

<h2>Available Events</h2>

<ul>

<?php while($event = mysqli_fetch_assoc($result)): ?>

    <li>

        <strong><?php echo $event['name']; ?></strong> <br>

        Date: <?php echo $event['date']; ?> <br>

        <a href="event_details.php?id=<?php echo $event['id']; ?>">View Details</a>

    </li>

<?php endwhile; ?>

</ul>


💻 2️ event_details.php — View details of a single event

<?php

session_start();

include('../db_connect.php');

 

if (!isset($_GET['id'])) {

    die('Event ID not provided.');

} 

$event_id = $_GET['id'];

$query = "SELECT * FROM events_table WHERE id = $event_id";

$result = mysqli_query($conn, $query);

$event = mysqli_fetch_assoc($result);

 

if (!$event) die('Event not found.');

?>

 <h2><?php echo $event['name']; ?></h2>

<p><?php echo $event['description']; ?></p>

<p>Date: <?php echo $event['date']; ?></p>

<p>Location: <?php echo $event['location']; ?></p>

 <a href="book_event.php?id=<?php echo $event['id']; ?>">Book This Event</a>


💻 3️ book_event.php — Book or register for an event

<?php

session_start();

include('../db_connect.php'); 

if (!isset($_SESSION['user_id'])) {

    die('You must log in to book an event.');

}

 if (!isset($_GET['id'])) {

    die('Event ID not provided.');

}

 $user_id = $_SESSION['user_id'];

$event_id = $_GET['id'];

$booking_date = date('Y-m-d');

$status = 'Booked';

 // Insert into bookings_table

$query = "INSERT INTO bookings_table (event_id, user_id, booking_date, status)

          VALUES ($event_id, $user_id, '$booking_date', '$status')";

 

if (mysqli_query($conn, $query)) {

    echo "Booking successful! <a href='my_bookings.php'>View My Bookings</a>";

} else {

    echo "Error: " . mysqli_error($conn);

}

?>


💻 4️ my_bookings.php — View user's bookings

<?php

session_start();

include('../db_connect.php');

 

if (!isset($_SESSION['user_id'])) {

    die('You must log in to view your bookings.');

} 

$user_id = $_SESSION['user_id'];

$query = "SELECT b.id, e.name, b.booking_date, b.status

          FROM bookings_table b

          JOIN events_table e ON b.event_id = e.id

          WHERE b.user_id = $user_id";

 $result = mysqli_query($conn, $query);

?> 

<h2>My Bookings</h2>

<table border="1">

    <tr>

        <th>Event Name</th>

        <th>Booking Date</th>

        <th>Status</th>

        <th>Action</th>

    </tr>

<?php while($booking = mysqli_fetch_assoc($result)): ?>

    <tr>

        <td><?php echo $booking['name']; ?></td>

        <td><?php echo $booking['booking_date']; ?></td>

        <td><?php echo $booking['status']; ?></td>

        <td>

            <?php if ($booking['status'] == 'Booked'): ?>

                <a href="cancel_booking.php?id=<?php echo $booking['id']; ?>">Cancel</a>

            <?php else: ?>

                N/A

            <?php endif; ?>

        </td>

    </tr>

<?php endwhile; ?>

</table>


💻 5️ cancel_booking.php — Cancel a booking

<?php

session_start();

include('../db_connect.php'); 

if (!isset($_SESSION['user_id'])) {

    die('You must log in to cancel bookings.');

}

 if (!isset($_GET['id'])) {

    die('Booking ID not provided.');

}

 $booking_id = $_GET['id'];

$user_id = $_SESSION['user_id'];

 // Check if booking belongs to user

$check = "SELECT * FROM bookings_table WHERE id = $booking_id AND user_id = $user_id";

$result = mysqli_query($conn, $check);

 

if (mysqli_num_rows($result) == 0) {

    die('Invalid booking or permission denied.');

}

 

// Update status

$query = "UPDATE bookings_table SET status = 'Cancelled' WHERE id = $booking_id";

 

if (mysqli_query($conn, $query)) {

    echo "Booking cancelled successfully. <a href='my_bookings.php'>Back to My Bookings</a>";

} else {

    echo "Error cancelling booking: " . mysqli_error($conn);

}

?>


 

Tags

Post a Comment

0Comments

Post a Comment (0)