Build a PHP Logistics Tracking & Delivery Management System for E‑Commerce
This tutorial walks you through building a PHP‑based logistics tracking and delivery management system for e‑commerce, covering database schema design, code for adding, updating, and querying shipment and delivery records, and demonstrates how to integrate these features to improve operational efficiency.
1. Logistics Tracking Implementation
1) Create Database Table
First, create a tracking table in the e‑commerce database to store logistics information.
CREATE TABLE tracking (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
order_id INT(11) NOT NULL,
status VARCHAR(255) NOT NULL,
update_time DATETIME
);2) Add Tracking Information
When an order status changes, insert a new tracking record.
// Get order ID and status
$order_id = $_POST['order_id'];
$status = $_POST['status'];
// Get current time
$update_time = date('Y-m-d H:i:s');
// Insert tracking info
$sql = "INSERT INTO tracking (order_id, status, update_time) VALUES ($order_id, '$status', '$update_time')";
$result = mysqli_query($conn, $sql);3) Query Tracking Information
Retrieve and display tracking records for a specific order.
// Get order ID
$order_id = $_POST['order_id'];
// Query tracking info
$sql = "SELECT * FROM tracking WHERE order_id = $order_id";
$result = mysqli_query($conn, $sql);
// Display tracking info
while ($row = mysqli_fetch_assoc($result)) {
echo $row['status'] . " - " . $row['update_time'] . "<br>";
}2. Delivery Management Implementation
1) Create Database Table
Create a delivery table to store delivery details.
CREATE TABLE delivery (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
order_id INT(11) NOT NULL,
courier VARCHAR(255) NOT NULL,
delivery_time DATETIME
);2) Add Delivery Information
Insert a delivery record when an order is shipped.
// Get order ID, courier and delivery time
$order_id = $_POST['order_id'];
$courier = $_POST['courier'];
$delivery_time = date('Y-m-d H:i:s');
// Insert delivery info
$sql = "INSERT INTO delivery (order_id, courier, delivery_time) VALUES ($order_id, '$courier', '$delivery_time')";
$result = mysqli_query($conn, $sql);3) Update Delivery Information
Modify delivery details, such as changing the courier.
// Get order ID and new courier
$order_id = $_POST['order_id'];
$new_courier = $_POST['new_courier'];
// Update delivery info
$sql = "UPDATE delivery SET courier = '$new_courier' WHERE order_id = $order_id";
$result = mysqli_query($conn, $sql);4) Query Delivery Information
Retrieve and display delivery records for a specific order.
// Get order ID
$order_id = $_POST['order_id'];
// Query delivery info
$sql = "SELECT * FROM delivery WHERE order_id = $order_id";
$result = mysqli_query($conn, $sql);
// Display delivery info
while ($row = mysqli_fetch_assoc($result)) {
echo $row['courier'] . " - " . $row['delivery_time'] . "<br>";
}Conclusion
By following this tutorial, you have learned how to implement logistics tracking and delivery management features using PHP. These functionalities are essential for enhancing user experience and operational efficiency in e‑commerce systems.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
