A dynamic Bus Booking System built with PHP, MySQL, AJAX, JavaScript, HTML, and CSS. This web platform lets users search routes, select seats on an interactive seat map, and complete bookings with real-time seat availability. Administrators can manage buses, routes, and bookings via a simple admin panel.
- User registration & login with password hashing
- Search buses by route and date
- Visual seat map and real-time seat availability (AJAX)
- Select multiple seats and view a live booking summary
- Booking confirmation page with saved booking records
- Admin-only dashboard (add/edit/delete buses and routes)
- View and manage all bookings (confirm/cancel/delete)
- Simple analytics (counts for users, buses, bookings)
- Frontend: HTML5, Tailwind CSS, (Bootstrap-ready), JavaScript, AJAX
- Backend: PHP (MySQLi, procedural)
- Database: MySQL
- Server: XAMPP / Apache (local development)
/var/www/html/advanced/
├── admin/
│ ├── dashboard.php # Admin overview
│ ├── buses.php # Manage buses (CRUD)
│ ├── routes.php # Manage routes (CRUD)
│ └── bookings.php # View/manage bookings
├── assets/
│ ├── css/
│ │ └── styles.css # Custom styles
│ └── js/
│ └── scripts.js # Client-side scripts
├── backend/
│ ├── config.php # DB connection
│ ├── logout.php # Logout handler
│ ├── process-booking.php # Booking processor (transactions)
│ └── get-available-seats.php # AJAX seat availability
├── index.php # Homepage + search
├── login.php # User login
├── register.php # User registration
├── search-results.php # Results + seat availability (AJAX)
├── book.php # Seat map and booking UI
├── booking-success.php # Booking confirmation
├── database.sql # Database schema + sample data
└── README.md
Tables and key columns:
users—id,name,email,password,is_admin,created_atroutes—id,from_location,to_location,departure_time,arrival_time,farebuses—id,bus_name,bus_number,total_seats,route_idbookings—id,user_id,bus_id,seat_number,booking_date,status,created_at
Note: The provided database.sql contains the full CREATE TABLE statements and some sample data.
- Place the project folder in your web server directory (e.g., XAMPP
htdocs):
# copy project to XAMPP htdocs
# cp -r advanced /opt/lampp/htdocs/advanced- Create the database and import schema:
- Open phpMyAdmin (http://localhost/phpmyadmin) and create a database named
bus_booking, then importdatabase.sql. Or use the MySQL CLI:
mysql -u root -p
CREATE DATABASE bus_booking;
EXIT;
mysql -u root -p bus_booking < /path/to/advanced/database.sql- Configure database connection:
Edit backend/config.php and set your credentials. Example:
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'bus_booking');
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>- Open the app in your browser:
http://localhost/advanced/
- Email:
[email protected](or[email protected]depending on your imported SQL) - Password:
admin123(the SQL file includes a hashed password example)
To create or reset an admin account, run in PHP or use phpMyAdmin to insert a user with a hashed password:
<?php
echo password_hash('admin123', PASSWORD_DEFAULT);
?>Then insert that hash into users.password with is_admin = 1.
- Users search for buses by selecting
From,To, andDateonindex.php. search-results.phpqueries matching buses and uses AJAX (backend/get-available-seats.php) to show live availability.- On
book.php, users see a seat map; booked seats are disabled. Selecting seats updates the booking summary client-side. backend/process-booking.phpruns a DB transaction: re-checks seat availability, inserts bookings, and commits or rolls back on error.- Admin pages live under
/adminand are protected by theis_adminsession flag.
- Passwords hashed with
password_hash() - Prepared statements (MySQLi) to prevent SQL injection
- Server-side validation and transaction handling for bookings
- Session checks for protected areas (admin and user-only pages)
Contributions are welcome. Suggested workflow:
- Fork the repository
- Create a branch for your feature/fix
- Open a pull request with a clear description
- You may want to add email notifications, payment gateway integration, and user booking history pages.
- Consider moving to an MVC structure or using a framework (Laravel) for larger projects.
This project is licensed under the MIT License. See the LICENSE file for details.
If you want, I can also add screenshots, a setup script, or an .env-based config loader. Tell me which you'd like next.
messages from users; Sajilo Booking yatra nepal