How to develop Basic Transport Management System in PHP + MySQL

Rashmi Mishra
0

 


🔧 Basic Transport Management System in PHP + MySQL


📁 Folder Structure

transport-system/

── db.php

── index.php

── add_vehicle.php

── add_driver.php

── add_route.php

── view_vehicles.php

── view_routes.php

└── style.css


⚙️ db.php (Database connection)

<?php

$conn = new mysqli("localhost", "root", "", "transport_db");

 

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

}

?>


🚚 add_vehicle.php

<?php include 'db.php'; ?>

<form method="POST">

    Vehicle Number: <input type="text" name="number"><br>

    Type: <input type="text" name="type"><br>

    Capacity: <input type="number" name="capacity"><br>

    <input type="submit" name="submit" value="Add Vehicle">

</form>

 

<?php

if (isset($_POST['submit'])) {

    $number = $_POST['number'];

    $type = $_POST['type'];

    $capacity = $_POST['capacity'];

    $conn->query("INSERT INTO vehicles(vehicle_number, vehicle_type, capacity, status)

                  VALUES ('$number', '$type', $capacity, 'available')");

    echo "Vehicle added successfully!";

}

?>


👨‍✈️ add_driver.php

<?php include 'db.php'; ?>

<form method="POST">

    Name: <input type="text" name="name"><br>

    License Number: <input type="text" name="license"><br>

    Phone: <input type="text" name="phone"><br>

    Vehicle ID: <input type="number" name="vehicle_id"><br>

    <input type="submit" name="submit" value="Add Driver">

</form>

 

<?php

if (isset($_POST['submit'])) {

    $name = $_POST['name'];

    $license = $_POST['license'];

    $phone = $_POST['phone'];

    $vehicle_id = $_POST['vehicle_id'];

    $conn->query("INSERT INTO drivers(name, license_number, phone, assigned_vehicle_id)

                  VALUES ('$name', '$license', '$phone', $vehicle_id)");

    echo "Driver added successfully!";

}

?>


🗺️ add_route.php

<?php include 'db.php'; ?>

<form method="POST">

    Origin: <input type="text" name="origin"><br>

    Destination: <input type="text" name="destination"><br>

    Departure Time: <input type="datetime-local" name="departure"><br>

    Arrival Time: <input type="datetime-local" name="arrival"><br>

    Vehicle ID: <input type="number" name="vehicle_id"><br>

    <input type="submit" name="submit" value="Add Route">

</form>

 

<?php

if (isset($_POST['submit'])) {

    $origin = $_POST['origin'];

    $destination = $_POST['destination'];

    $departure = $_POST['departure'];

    $arrival = $_POST['arrival'];

    $vehicle_id = $_POST['vehicle_id'];

    $conn->query("INSERT INTO routes(origin, destination, departure_time, arrival_time, vehicle_id)

                  VALUES ('$origin', '$destination', '$departure', '$arrival', $vehicle_id)");

    echo "Route added successfully!";

}

?>


📋 view_vehicles.php

<?php include 'db.php';

$result = $conn->query("SELECT * FROM vehicles");

 

echo "<h2>Vehicles</h2><table border='1'>

<tr><th>ID</th><th>Number</th><th>Type</th><th>Capacity</th><th>Status</th></tr>";

while($row = $result->fetch_assoc()) {

    echo "<tr>

        <td>{$row['id']}</td>

        <td>{$row['vehicle_number']}</td>

        <td>{$row['vehicle_type']}</td>

        <td>{$row['capacity']}</td>

        <td>{$row['status']}</td>

    </tr>";

}

echo "</table>";

?>


🧭 view_routes.php

<?php include 'db.php';

$result = $conn->query("SELECT * FROM routes");

 

echo "<h2>Routes</h2><table border='1'>

<tr><th>ID</th><th>From</th><th>To</th><th>Departure</th><th>Arrival</th><th>Vehicle</th></tr>";

while($row = $result->fetch_assoc()) {

    echo "<tr>

        <td>{$row['id']}</td>

        <td>{$row['origin']}</td>

        <td>{$row['destination']}</td>

        <td>{$row['departure_time']}</td>

        <td>{$row['arrival_time']}</td>

        <td>{$row['vehicle_id']}</td>

    </tr>";

}

echo "</table>";

?>



🚦 Transport Management System – Modules


1. Authentication Module (optional but recommended)

  • Purpose: Secure access to the system for Admins and Users.
  • Features:
    • Admin/User login
    • Role-based access control
    • Registration (if needed)
    • Password reset

2. Vehicle Management Module

  • Purpose: Manage all vehicles in the transport fleet.
  • Features:
    • Add a new vehicle
    • View all vehicles
    • Edit vehicle details
    • Delete vehicle record
    • Update vehicle status (available, on duty, under maintenance)

3. Driver Management Module

  • Purpose: Maintain and assign drivers to vehicles.
  • Features:
    • Add a new driver
    • View all drivers
    • Assign driver to a vehicle
    • Edit/Delete driver info
    • Check driver availability

4. Route Management Module

  • Purpose: Create and manage transportation routes.
  • Features:
    • Add a route (origin → destination)
    • Assign vehicle and driver to a route
    • Set departure and arrival times
    • View/Edit/Delete route details

5. Transport Scheduling Module

  • Purpose: Schedule and manage vehicle movements.
  • Features:
    • Assign routes to vehicles and drivers
    • Set trip frequency or timing
    • Track running/active schedules

6. Booking Module (for user panel – optional)

  • Purpose: Allow users to book transport services (for buses, logistics, etc.)
  • Features:
    • Search for routes
    • View vehicle availability
    • Book a transport service
    • Cancel bookings

7. Trip History & Logs Module

  • Purpose: Maintain history of trips, vehicle movements, and driver assignments.
  • Features:
    • View past trips
    • Filter by date/vehicle/driver
    • Generate reports

8. Reports Module

  • Purpose: Generate operational and administrative reports.
  • Features:
    • Vehicle usage reports
    • Driver activity reports
    • Route and trip summary
    • Booking and revenue reports (if applicable)

9. User Management Module (Admin panel only)

  • Purpose: Manage admin and user accounts.
  • Features:
    • Add new users/admins
    • View/edit/delete users
    • Reset passwords
    • Assign roles

10. Notification/Alert Module (optional)

  • Purpose: Send reminders or alerts (maintenance due, route reminders, etc.)
  • Features:
    • Email/SMS alerts
    • Popup dashboard alerts

11. Settings Module

  • Purpose: Configure system-wide options.
  • Features:
    • Change system name/logo
    • Set time zones or regional formats
    • Configure default status for vehicles, drivers

📁 Transport Management System – Project Folder Structure (Without MVC)

transport-management-system/

── db.php                     # Database connection file

── index.php                  # Dashboard or landing page

── css/

   └── style.css              # Main stylesheet

── includes/                  # Reusable parts of pages (like header, footer, sidebar)

   ── header.php

   ── footer.php

   └── sidebar.php

── auth/                      # Login and logout functionality

   ── login.php

   ── logout.php

   └── login_process.php

── vehicles/                  # Vehicle management module

   ── add_vehicle.php

   ── edit_vehicle.php

   ── delete_vehicle.php

   ── view_vehicles.php

   └── vehicle_process.php    # Handles vehicle form submission

── drivers/                   # Driver management module

   ── add_driver.php

   ── edit_driver.php

   ── delete_driver.php

   ── view_drivers.php

   └── driver_process.php

── routes/                    # Route management module

   ── add_route.php

   ── edit_route.php

   ── delete_route.php

   ── view_routes.php

   └── route_process.php

── schedule/                  # Scheduling module

   ── add_schedule.php

   ── view_schedule.php

   └── schedule_process.php

── bookings/                  # Booking module (optional)

   ── book_transport.php

   ── my_bookings.php

   └── booking_process.php

── reports/                   # Reports module

   ── vehicle_report.php

   ── driver_report.php

   ── route_report.php

   └── booking_report.php

── users/                     # User/Admin management

   ── add_user.php

   ── view_users.php

   ── edit_user.php

   └── user_process.php

└── config/                    # Configuration and utility files

    ── session_check.php      # For checking if the user is logged in

    └── constants.php          # For app-wide constants (like base URL, app name)


What Each Folder Does

Folder/File

Purpose

db.php

Handles database connection. Include this in every file that needs DB access.

includes/

Contains reusable HTML parts like header, footer, sidebar.

auth/

User authentication (login/logout)

vehicles/

CRUD operations for vehicle records

drivers/

CRUD operations for driver records

routes/

CRUD for managing transport routes

schedule/

Manage transport schedules

bookings/ (optional)

User-side booking and viewing of trips

reports/

Report generation for admin

users/

Add, manage system users/admins

config/

Configuration files like session check, app constants, helper functions




🚦 Transport Management System – Project Structure with MVC

transport-management-system/

── index.php                           # Entry point for all requests (Front Controller)

── .htaccess                           # URL rewriting to route requests to index.php (Apache)

── app/                                # Application-specific files (MVC lives here)

   ── controllers/                    # All controllers

      ── AuthController.php

      ── VehicleController.php

      ── DriverController.php

      ── RouteController.php

      ── ScheduleController.php

      ── BookingController.php

      └── ReportController.php

  

   ── models/                         # All model classes (database interaction)

      ── User.php

      ── Vehicle.php

      ── Driver.php

      ── Route.php

      ── Schedule.php

      └── Booking.php

  

   ── views/                          # Views grouped by controller/module

      ── auth/

         ── login.php

         └── register.php

      ── vehicles/

         ── index.php

         ── add.php

         ── edit.php

         └── view.php

      ── drivers/

      ── routes/

      ── schedule/

      ── bookings/

      └── reports/

  

   ── core/                           # Core MVC classes and libraries

      ── Controller.php              # Base controller class

      ── Model.php                   # Base model class

      ── View.php                    # Handles rendering views

      ── App.php                     # Main application class

      └── Database.php               # Database connection (PDO)

  

   └── config/                         # Configuration files

       ── config.php                 # App-wide constants and DB config

       └── routes.php                 # URL routing

── public/                             # Publicly accessible folder (images, CSS, JS)

   ── css/

      └── style.css

   ── js/

   ── images/

   └── uploads/                        # For uploaded documents/images

└── storage/                            # Log files, cache, temp data

    ── logs/

    └── uploads/


Explanation of MVC Components

Folder

Description

controllers/

Handles user requests, processes data with models, and loads the correct view.

models/

Handles all business logic and database operations. Each model = 1 table.

views/

Displays data to users. Each module has its own folder.

core/

Custom framework logic (mini-framework) — handles routing, controller loading, etc.

public/

Public assets like stylesheets, JS files, uploaded images.

index.php

Main entry point — all routes go through this file.

.htaccess

Rewrites all requests to index.php (if using Apache).


🔄 Routing Example

When a user goes to:

http://yourdomain.com/vehicle/add

It goes to:

VehicleController.php → add() method → loads views/vehicles/add.php


🧠 Suggestions

  • Use PDO for database interaction (safe and object-oriented).
  • Add a Session helper to manage login sessions securely.
  • Add CSRF tokens in forms for security.
  • Consider using autoload (like Composer or your own) to load classes.


🚦 Project Overview: Transport Management System (TMS)

Objective:

The Transport Management System is a web-based application designed to help organizations manage and monitor their vehicles, drivers, routes, schedules, and transport bookings efficiently. It helps automate daily transport operations and reduces paperwork.


👨‍💼 Target Users:

  • Admin/Transport Manager: Can manage vehicles, drivers, routes, schedules, bookings, and generate reports.
  • (Optional) Employees or Users: Can view schedules or make bookings if such a module is included.

🔧 Core Features / Modules:

Module

Description

Authentication

Login/logout for admin (and optionally users).

Vehicle Management

Add, update, delete, and list vehicles with details like vehicle number, type, capacity, etc.

Driver Management

Manage drivers’ details like name, license number, contact info, etc.

Route Management

Define transport routes with source, destination, and distance.

Schedule Management

Schedule transport services, assign drivers and vehicles to a route with date and time.

Booking Management (Optional)

Users can book transport service for specific routes/dates.

Reports Module

Generate printable reports for vehicles, routes, drivers, and bookings.

User Management (Optional)

Add multiple admin users with roles/permissions.


🛠️ Technology Stack:

Layer

Technology

Frontend

HTML, CSS, Bootstrap (for UI styling)

Backend

PHP (Core PHP or PHP with MVC structure)

Database

MySQL (Using phpMyAdmin or directly via SQL)

Server

XAMPP / LAMP / WAMP or any Apache + PHP server


🗂️ Deployment:

  • Localhost using XAMPP/WAMP
  • OR on a live web server with PHP & MySQL support

Benefits of the System:

  • Reduces paperwork and manual errors
  • Centralizes all transport-related data
  • Improves efficiency and saves time
  • Easy to manage schedules and assignments
  • Can generate useful reports for management


🧩 ER Diagram (Entity Relationship Diagram) – Overview

Here’s a text-based explanation of the main entities and their relationships:

[Admin/User]

     |

     |  (Managed by)

     v

[Vehicle] ← Assigned → [Driver]

     |

     |  (Assigned to)

     v

[Route] ← Scheduled In → [Schedule] ← Booked By (optional) ← [Booking/User]


🗃️ Database Tables Design

1. users (for admin or user login)

Field

Type

Description

id

INT, PK, AI

Unique user ID

name

VARCHAR(100)

Full name

email

VARCHAR(100)

Login email

password

VARCHAR(255)

Hashed password

role

ENUM

'admin', 'user'

created_at

DATETIME

Date added


2. vehicles

Field

Type

Description

id

INT, PK, AI

Vehicle ID

vehicle_number

VARCHAR(50)

Registration number

type

VARCHAR(50)

Bus, Van, Truck, etc.

capacity

INT

Number of seats/load

status

ENUM

'active', 'inactive'

created_at

DATETIME

Date added


3. drivers

Field

Type

Description

id

INT, PK, AI

Driver ID

name

VARCHAR(100)

Driver name

license_no

VARCHAR(100)

Driving license number

contact

VARCHAR(15)

Phone number

address

TEXT

Address details

created_at

DATETIME

Date added


4. routes

Field

Type

Description

id

INT, PK, AI

Route ID

source

VARCHAR(100)

Starting point

destination

VARCHAR(100)

Ending point

distance_km

INT

Distance in kilometers

created_at

DATETIME

Date added


5. schedules

Field

Type

Description

id

INT, PK, AI

Schedule ID

vehicle_id

INT, FK

FK to vehicles(id)

driver_id

INT, FK

FK to drivers(id)

route_id

INT, FK

FK to routes(id)

schedule_date

DATE

Scheduled date

time_slot

VARCHAR(50)

Morning, Evening, etc.

created_at

DATETIME

Date scheduled


6. bookings (optional for user-facing system)

Field

Type

Description

id

INT, PK, AI

Booking ID

user_id

INT, FK

FK to users(id)

schedule_id

INT, FK

FK to schedules(id)

seats_booked

INT

Number of seats booked

booking_date

DATETIME

When the booking happened


🔗 Relationships

  • One vehicle can have many schedules
  • One driver can have many schedules
  • One route can be reused in many schedules
  • One user can make many bookings
  • Each booking belongs to one schedule


🛠️ SQL Code – Table Creation

-- 1. USERS TABLE

CREATE TABLE users (

    id INT AUTO_INCREMENT PRIMARY KEY,

    name VARCHAR(100) NOT NULL,

    email VARCHAR(100) UNIQUE NOT NULL,

    password VARCHAR(255) NOT NULL,

    role ENUM('admin', 'user') DEFAULT 'admin',

    created_at DATETIME DEFAULT CURRENT_TIMESTAMP

);

 

-- 2. VEHICLES TABLE

CREATE TABLE vehicles (

    id INT AUTO_INCREMENT PRIMARY KEY,

    vehicle_number VARCHAR(50) NOT NULL UNIQUE,

    type VARCHAR(50) NOT NULL,

    capacity INT NOT NULL,

    status ENUM('active', 'inactive') DEFAULT 'active',

    created_at DATETIME DEFAULT CURRENT_TIMESTAMP

);

 

-- 3. DRIVERS TABLE

CREATE TABLE drivers (

    id INT AUTO_INCREMENT PRIMARY KEY,

    name VARCHAR(100) NOT NULL,

    license_no VARCHAR(100) NOT NULL UNIQUE,

    contact VARCHAR(15),

    address TEXT,

    created_at DATETIME DEFAULT CURRENT_TIMESTAMP

);

 

-- 4. ROUTES TABLE

CREATE TABLE routes (

    id INT AUTO_INCREMENT PRIMARY KEY,

    source VARCHAR(100) NOT NULL,

    destination VARCHAR(100) NOT NULL,

    distance_km INT NOT NULL,

    created_at DATETIME DEFAULT CURRENT_TIMESTAMP

);

 

-- 5. SCHEDULES TABLE

CREATE TABLE schedules (

    id INT AUTO_INCREMENT PRIMARY KEY,

    vehicle_id INT,

    driver_id INT,

    route_id INT,

    schedule_date DATE NOT NULL,

    time_slot VARCHAR(50),

    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,

    FOREIGN KEY (vehicle_id) REFERENCES vehicles(id) ON DELETE CASCADE,

    FOREIGN KEY (driver_id) REFERENCES drivers(id) ON DELETE CASCADE,

    FOREIGN KEY (route_id) REFERENCES routes(id) ON DELETE CASCADE

);

 

-- 6. BOOKINGS TABLE (Optional)

CREATE TABLE bookings (

    id INT AUTO_INCREMENT PRIMARY KEY,

    user_id INT,

    schedule_id INT,

    seats_booked INT NOT NULL,

    booking_date DATETIME DEFAULT CURRENT_TIMESTAMP,

    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,

    FOREIGN KEY (schedule_id) REFERENCES schedules(id) ON DELETE CASCADE

);


Notes:

  • AUTO_INCREMENT is used for primary keys.
  • DEFAULT CURRENT_TIMESTAMP automatically sets the created date.
  • ON DELETE CASCADE ensures related records are deleted when a parent record is removed.
  • The bookings table is optional and only needed if users can make reservations.

Post a Comment

0Comments

Post a Comment (0)