based on this inf databass (-- phpMyAdmin SQL Dump -- version 5.2.1 --…
- User
based on this inf databass (-- phpMyAdmin SQL Dump -- version 5.2.1 -- https://www.phpmyadmin.net/
-- Host: 127.0.0.1:3306 -- Generation Time: Nov 06, 2024 at 04:20 PM -- Server version: 10.11.9-MariaDB -- PHP Version: 7.2.34
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /; /!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /; /!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /; /!40101 SET NAMES utf8mb4 */;
-- -- Database:
u406552082_kaakalia
-- -- Table structure for table
customersCREATE TABLE
customers(idint(11) NOT NULL,namevarchar(100) NOT NULL,contactvarchar(50) DEFAULT NULL,delivery_addresstext DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- -- Table structure for table
ordersCREATE TABLE
orders(idint(11) NOT NULL,customer_idint(11) NOT NULL,product_idint(11) NOT NULL,statusenum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',order_datedatetime DEFAULT current_timestamp(),delivery_datetimedatetime DEFAULT NULL,delivery_datedate DEFAULT NULL,quantityint(11) NOT NULL DEFAULT 1,packaging_preferencesvarchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- -- Table structure for table
order_itemsCREATE TABLE
order_items(idint(11) NOT NULL,order_idint(11) NOT NULL,product_idint(11) NOT NULL,quantityint(11) NOT NULL,packaging_preferencesvarchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- -- Table structure for table
productsCREATE TABLE
products(idint(11) NOT NULL,namevarchar(100) NOT NULL,sizevarchar(50) DEFAULT NULL,pricedecimal(10,2) NOT NULL,categoryvarchar(50) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- -- Table structure for table
usersCREATE TABLE
users(idint(11) NOT NULL,usernamevarchar(50) NOT NULL,passwordvarchar(255) NOT NULL,roleenum('admin','staff') NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;-- -- Indexes for dumped tables
-- -- Indexes for table
customersALTER TABLE
customersADD PRIMARY KEY (id);-- -- Indexes for table
ordersALTER TABLE
ordersADD PRIMARY KEY (id), ADD KEYcustomer_id(customer_id);-- -- Indexes for table
order_itemsALTER TABLE
order_itemsADD PRIMARY KEY (id), ADD KEYorder_id(order_id), ADD KEYproduct_id(product_id);-- -- Indexes for table
productsALTER TABLE
productsADD PRIMARY KEY (id);-- -- Indexes for table
usersALTER TABLE
usersADD PRIMARY KEY (id), ADD UNIQUE KEYusername(username);-- -- AUTO_INCREMENT for dumped tables
-- -- AUTO_INCREMENT for table
customersALTER TABLE
customersMODIFYidint(11) NOT NULL AUTO_INCREMENT;-- -- AUTO_INCREMENT for table
ordersALTER TABLE
ordersMODIFYidint(11) NOT NULL AUTO_INCREMENT;-- -- AUTO_INCREMENT for table
order_itemsALTER TABLE
order_itemsMODIFYidint(11) NOT NULL AUTO_INCREMENT;-- -- AUTO_INCREMENT for table
productsALTER TABLE
productsMODIFYidint(11) NOT NULL AUTO_INCREMENT;-- -- AUTO_INCREMENT for table
usersALTER TABLE
usersMODIFYidint(11) NOT NULL AUTO_INCREMENT;-- -- Constraints for dumped tables
-- -- Constraints for table
ordersALTER TABLE
ordersADD CONSTRAINTorders_ibfk_1FOREIGN KEY (customer_id) REFERENCEScustomers(id), ADD CONSTRAINTorders_ibfk_2FOREIGN KEY (product_id) REFERENCESproducts(id);-- -- Constraints for table
order_itemsALTER TABLE
order_itemsADD CONSTRAINTorder_items_ibfk_1FOREIGN KEY (order_id) REFERENCESorders(id) ON DELETE CASCADE, ADD CONSTRAINTorder_items_ibfk_2FOREIGN KEY (product_id) REFERENCESproducts(id) ON DELETE CASCADE; COMMIT;/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /; /!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /; /!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;) I want to add delete record in the codes (<?php // public/orders/view_orders.php
// Enable error reporting for debugging (disable in production) ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
// Include authentication and database connection require_once DIR . '/../../includes/auth.php'; require_once DIR . '/../../includes/db_connect.php';
// Handle status update if (isset(_GET['action']) && _GET['action'] === 'update_status') { _GET['order_id']) ? intval(new_status = isset(_GET['new_status']) : '';
// Validate new_status $valid_statuses = ['Pending', 'In Progress', 'Completed', 'Delivered']; if ($order_id > 0 && in_array($new_status, $valid_statuses)) { // Optional: If setting to 'Delivered', ensure delivery_datetime is set if ($new_status === 'Delivered') { $check_sql = "SELECT delivery_datetime FROM orders WHERE id = ?"; $check_stmt = $conn->prepare($check_sql); $check_stmt->bind_param("i", $order_id); $check_stmt->execute(); $check_result = $check_stmt->get_result(); if ($check_result->num_rows == 1) { $order = $check_result->fetch_assoc(); if (empty($order['delivery_datetime'])) { header("Location: view_orders.php?error=3"); // Delivery datetime not set exit(); } } $check_stmt->close(); } // Update status using prepared statement $update_sql = "UPDATE orders SET status = ? WHERE id = ?"; $stmt = $conn->prepare($update_sql); if ($stmt) { $stmt->bind_param("si", $new_status, $order_id); if ($stmt->execute()) { $stmt->close(); header("Location: view_orders.php?success=1"); exit(); } else { $stmt->close(); header("Location: view_orders.php?error=1"); exit(); } } else { header("Location: view_orders.php?error=2"); exit(); } } else { header("Location: view_orders.php?error=2"); exit(); }}
// Fetch orders with customer and product details orders_result = orders_sql);
// Fetch order items for all orders order_items_result = order_items_sql);
// Organize order items by order_id order_items_result && order_items_result->num_rows > 0) { while (item = order_items_result->fetch_assoc()) { order_items[item; } } ?>
<!-- Google Fonts --> <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap" rel="stylesheet"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="/kaak_alia_management_system/assets/bootstrap/css/bootstrap.min.css"> <!-- Bootstrap Icons --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css"> <!-- Embedded Custom Styles --> <style> /* --------------------------------------------------- 1. CSS Variables for Consistent Design ---------------------------------------------------- */ :root { --dark-gray: #333333; /* Header and Footer Background */ --soft-brown: #FFD166; /* Add New Order Button */ --blue: #118AB2; /* View Orders Button */ --green: #06D6A0; /* Manage Products Button */ --orange: #F4A261; /* Manage Users Button */ --red-pink: #EF476F; /* Generate Reports Button */ --main-text: #333333; --secondary-text: #666666; --white: #FFFFFF; --light-gray: #F9F9F9; --divider-color: #FFD166; --transition-speed: 0.3s; --hover-shadow: rgba(0, 0, 0, 0.2); } /* --------------------------------------------------- 2. Global Styles ---------------------------------------------------- */ body { font-family: 'Cairo', sans-serif; background: linear-gradient(to bottom, #f5f7fa, #c3cfe2); margin: 0; padding: 30px; box-sizing: border-box; } /* --------------------------------------------------- 3. Header Styles ---------------------------------------------------- */ .header { padding: 20px 30px; background-color: var(--dark-gray); border-radius: 8px; text-align: center; margin-bottom: 30px; color: var(--white); font-size: 24px; font-weight: bold; } /* --------------------------------------------------- 4. Success and Error Alerts ---------------------------------------------------- */ .alert-success-custom { background-color: var(--green); color: var(--white); border-radius: 8px; padding: 15px 20px; margin-bottom: 20px; text-align: center; width: 70%; margin: 20px auto; } .alert-error-custom { background-color: var(--red-pink); color: var(--white); border-radius: 8px; padding: 15px 20px; margin-bottom: 20px; text-align: center; width: 70%; margin: 20px auto; } /* --------------------------------------------------- 5. Recent Orders Table ---------------------------------------------------- */ .recent-orders-section { background-color: #ffffff; border-radius: 8px; padding: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } .recent-orders-section h4 { font-size: 16px; font-weight: bold; color: var(--main-text); margin-bottom: 15px; } .recent-orders-section table { width: 100%; border-collapse: collapse; } .recent-orders-section th, .recent-orders-section td { padding: 12px; text-align: left; font-size: 16px; } .recent-orders-section th { background-color: var(--dark-gray); color: var(--white); font-weight: bold; } .recent-orders-section tr:nth-child(even) { background-color: var(--light-gray); } .recent-orders-section tr:hover { background-color: #e6f7ff; } .recent-orders-section td { font-size: 14px; color: var(--main-text); vertical-align: top; } .recent-orders-section .view-all { display: block; text-align: right; margin-top: 10px; font-size: 14px; color: var(--blue); font-weight: bold; text-decoration: none; transition: color 0.2s; } .recent-orders-section .view-all:hover { color: #075985; } /* Badge Styles */ .badge-status-pending { background-color: #FFD166; color: var(--white); padding: 5px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; } .badge-status-in-progress { background-color: #118AB2; color: var(--white); padding: 5px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; } .badge-status-completed { background-color: #06D6A0; color: var(--white); padding: 5px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; } .badge-status-delivered { background-color: #EF476F; color: var(--white); padding: 5px 10px; border-radius: 12px; font-size: 12px; font-weight: bold; } /* --------------------------------------------------- 6. Footer Styles ---------------------------------------------------- */ .footer { background-color: var(--dark-gray); color: var(--white); padding: 15px; text-align: center; border-radius: 8px; font-size: 14px; line-height: 20px; margin-top: 40px; } /* --------------------------------------------------- 7. Responsive Design Enhancements ---------------------------------------------------- */ @media (max-width: 768px) { /* Align form elements for tablets */ .form-label, .form-control, .submit-button, .alert-success-custom, .alert-error-custom { width: 90%; margin: 0 auto 15px auto; } } @media (max-width: 480px) { /* Align form elements for mobile devices */ .header { padding: 15px 20px; font-size: 20px; } .header h1 { font-size: 20px; } .recent-orders-section th, .recent-orders-section td { font-size: 12px; padding: 8px; } .recent-orders-section .view-all { font-size: 14px; } } </style><!-- Header --> <div class="header"> View Orders </div> <!-- Display Success or Error Messages --> <?php if (isset($_GET['success']) && $_GET['success'] == 1): ?> <div class="alert-success-custom">Order status updated successfully!</div> <?php endif; ?> <?php if (isset($_GET['error'])): ?> <?php if ($_GET['error'] == 1): ?> <div class="alert-error-custom">Failed to update order status.</div> <?php elseif ($_GET['error'] == 2): ?> <div class="alert-error-custom">Invalid status selected.</div> <?php elseif ($_GET['error'] == 3): ?> <div class="alert-error-custom">Cannot set status to Delivered without a delivery date and time.</div> <?php endif; ?> <?php endif; ?> <!-- Container --> <div class="recent-orders-section"> <h4>All Orders</h4> <table> <thead> <tr> <th>ID</th> <th>Customer</th> <th>Contact</th> <th>Delivery Address</th> <th>Primary Product</th> <th>Additional Products</th> <th>Status</th> <th>Order Date</th> <th>Delivery DateTime</th> <th>Actions</th> </tr> </thead> <tbody> <?php if ($orders_result && $orders_result->num_rows > 0): ?> <?php while($order = $orders_result->fetch_assoc()): ?> <tr> <td><?= htmlspecialchars($order['order_id']) ?></td> <td><?= htmlspecialchars($order['customer_name']) ?></td> <td><?= htmlspecialchars($order['contact']) ?></td> <td><?= nl2br(htmlspecialchars($order['delivery_address'])) ?></td> <td> <?= htmlspecialchars($order['primary_product_name'] . " - " . $order['primary_product_size'] . " (" . number_format(get_product_price($conn, $order['primary_product_id']), 2) . " KD)") ?><br> Quantity: <?= htmlspecialchars($order['primary_quantity']) ?><br> Packaging: <?= htmlspecialchars($order['primary_packaging_preferences']) ?> </td> <td> <?php if (isset($order_items[$order['order_id']])) { foreach ($order_items[$order['order_id']] as $item) { echo htmlspecialchars($item['product_name'] . " - " . $item['product_size'] . " (" . number_format(get_product_price($conn, $item['product_id']), 2) . " KD)") . "<br>"; echo "Quantity: " . htmlspecialchars($item['quantity']) . "<br>"; echo "Packaging: " . htmlspecialchars($item['packaging_preferences']) . "<br><br>"; } } else { echo "None"; } ?> </td> <td> <?php switch ($order['status']) { case 'Pending': echo '<span class="badge-status-pending">Pending</span>'; break; case 'In Progress': echo '<span class="badge-status-in-progress">In Progress</span>'; break; case 'Completed': echo '<span class="badge-status-completed">Completed</span>'; break; case 'Delivered': echo '<span class="badge-status-delivered">Delivered</span>'; break; default: echo '<span class="badge bg-light text-dark">Unknown</span>'; } ?> </td> <td><?= date("d M Y, h:i A", strtotime($order['order_date'])) ?></td> <td><?= $order['delivery_datetime'] ? date("d M Y, h:i A", strtotime($order['delivery_datetime'])) : 'N/A' ?></td> <td> <!-- Edit Button --> <a href="edit_order.php?id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-outline-secondary" title="Edit Order"> <i class="bi bi-pencil-fill"></i> </a> <!-- Change Status Dropdown --> <div class="btn-group"> <button type="button" class="btn btn-sm btn-outline-info dropdown-toggle" data-bs-toggle="dropdown" title="Change Status"> <i class="bi bi-arrow-repeat"></i> </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Pending">Pending</a></li> <li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=In Progress">In Progress</a></li> <li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Completed">Completed</a></li> <li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Delivered">Delivered</a></li> </ul> </div> </td> </tr> <?php endwhile; ?> <?php else: ?> <tr> <td colspan="10" class="text-center">No orders found.</td> </tr> <?php endif; ?> </tbody> </table> <!-- <a href="#" class="view-all">View All Orders</a> --> <!-- Removed since all orders are already displayed --> </div> <!-- Footer --> <div class="footer"> © 2024 Kaak Alia Bakery. All rights reserved. </div> <!-- Bootstrap JS Bundle --> <script src="/kaak_alia_management_system/assets/bootstrap/js/bootstrap.bundle.min.js"></script> <!-- Initialize Bootstrap Tooltip (Optional) --> <script> var tooltipTriggerList = [].slice.call(document.querySelectorAll('[title]')) var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) }) </script> - Assistant
To incorporate a functionality that allows you to delete an order from the existing setup, you need to add a delete action in your
view_orders.phpfile. Here is how you can accomplish that by creating a separate PHP file that handles the delete action:Step 1: Create a new PHP file to handle order deletion
Create a new PHP file named
delete_order.phpthat will handle the deletion of orders.<?php // public/orders/delete_order.php // Enable error reporting for debugging (disable in production) ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); // Include authentication and database connection require_once __DIR__ . '/../../includes/auth.php'; require_once __DIR__ . '/../../includes/db_connect.php'; // Check if the order ID is set if (isset($_GET['order_id'])) { $order_id = intval($_GET['order_id']); // Delete order items associated with the order $delete_order_items_sql = "DELETE FROM order_items WHERE order_id = ?"; $stmt = $conn->prepare($delete_order_items_sql); $stmt->bind_param("i", $order_id); $stmt->execute(); $stmt->close(); // Delete the order $delete_order_sql = "DELETE FROM orders WHERE id = ?"; $stmt = $conn->prepare($delete_order_sql); $stmt->bind_param("i", $order_id); if ($stmt->execute()) { $stmt->close(); header("Location: view_orders.php?success=2"); // Redirect with success message } else { $stmt->close(); header("Location: view_orders.php?error=4"); // Redirect with error message } } else { header("Location: view_orders.php?error=5"); // Redirect with another error message } exit(); ?>Step 2: Update
view_orders.phpto include delete functionalityModify your
view_orders.phpfile to include a "Delete" button in the actions column. Update the success and error messages at the top as necessary.Find and update the
<td>in the "Actions" column with the following:<td> <!-- Edit Button --> <a href="edit_order.php?id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-outline-secondary" title="Edit Order"> <i class="bi bi-pencil-fill"></i> </a> <!-- Change Status Dropdown --> <div class="btn-group"> <button type="button" class="btn btn-sm btn-outline-info dropdown-toggle" data-bs-toggle="dropdown" title="Change Status"> <i class="bi bi-arrow-repeat"></i> </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Pending">Pending</a></li> <li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=In Progress">In Progress</a></li> <li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Completed">Completed</a></li> <li><a class="dropdown-item" href="?action=update_status&order_id=<?= htmlspecialchars($order['order_id']) ?>&new_status=Delivered">Delivered</a></li> </ul> </div> <!-- Delete Button --> <a href="delete_order.php?order_id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-outline-danger" title="Delete Order" onclick="return confirm('Are you sure you want to delete this order?');"> <i class="bi bi-trash-fill"></i> </a> </td>Step 3: Update Success and Error Messages
Adjust the success and error messages at the top of
view_orders.php:<?php if (isset($_GET['success']) && $_GET['success'] == 1): ?> <div class="alert-success-custom">Order status updated successfully!</div> <?php elseif (isset($_GET['success']) && $_GET['success'] == 2): ?> <div class="alert-success-custom">Order deleted successfully!</div> <?php endif; ?> <?php if (isset($_GET['error'])): ?> <?php if ($_GET['error'] == 1): ?> <div class="alert-error-custom">Failed to update order status.</div> <?php elseif ($_GET['error'] == 2): ?> <div class="alert-error-custom">Invalid status selected.</div> <?php elseif ($_GET['error'] == 3): ?> <div class="alert-error-custom">Cannot set status to Delivered without a delivery date and time.</div> <?php elseif ($_GET['error'] == 4): ?> <div class="alert-error-custom">Failed to delete order.</div> <?php elseif ($_GET['error'] == 5): ?> <div class="alert-error-custom">No order specified.</div> <?php endif; ?> <?php endif; ?>Final Note:
Make sure to protect these pages with appropriate authentication and authorization logic to prevent unauthorized access. The order deletion will also delete any associated order items due to the foreign key constraint with
ON DELETE CASCADE.Ensure the new PHP file (
delete_order.php) is saved in the correct directory (e.g.,public/orders/) and is accessible based on your server's configuration and routing. - User
i want to create file called view_order_customer, this show all info of this order
- Assistant
To create a detailed view for a specific order, you can create a new PHP file, which we'll call
view_order_customer.php. This file will fetch and display all relevant information about the selected order, including the customer details, primary product, additional products, and their statuses.Step 1: Create the
view_order_customer.phpFileCreate a new PHP file named
view_order_customer.phpand use the code below to display the full details of a specific order.<?php // public/orders/view_order_customer.php // Enable error reporting for debugging (disable in production) ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); // Include authentication and database connection require_once __DIR__ . '/../../includes/auth.php'; require_once __DIR__ . '/../../includes/db_connect.php'; // Check if order_id is given $order_id = isset($_GET['order_id']) ? intval($_GET['order_id']) : 0; if ($order_id <= 0) { header("Location: view_orders.php?error=6"); // Invalid order ID exit(); } // Fetch order details along with customer and product information $order_sql = " SELECT orders.id AS order_id, orders.status, orders.order_date, orders.delivery_datetime, customers.name AS customer_name, customers.contact, customers.delivery_address, orders.product_id AS primary_product_id, orders.quantity AS primary_quantity, orders.packaging_preferences AS primary_packaging_preferences, products.name AS primary_product_name, products.size AS primary_product_size FROM orders JOIN customers ON orders.customer_id = customers.id JOIN products ON orders.product_id = products.id WHERE orders.id = ? "; $order_stmt = $conn->prepare($order_sql); $order_stmt->bind_param("i", $order_id); $order_stmt->execute(); $order_result = $order_stmt->get_result(); $order = $order_result->fetch_assoc(); $order_stmt->close(); if (!$order) { header("Location: view_orders.php?error=7"); // Order not found exit(); } // Fetch additional order items $order_items_sql = " SELECT order_items.product_id, order_items.quantity, order_items.packaging_preferences, products.name AS product_name, products.size AS product_size FROM order_items JOIN products ON order_items.product_id = products.id WHERE order_items.order_id = ? "; $item_stmt = $conn->prepare($order_items_sql); $item_stmt->bind_param("i", $order_id); $item_stmt->execute(); $order_items_result = $item_stmt->get_result(); $order_items = []; while ($item = $order_items_result->fetch_assoc()) { $order_items[] = $item; } $item_stmt->close(); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Order #<?= htmlspecialchars($order['order_id']) ?> Details - Kaak Alia Management System</title> <link rel="stylesheet" href="/kaak_alia_management_system/assets/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css"> <style> body { font-family: 'Cairo', sans-serif; background: linear-gradient(to bottom, #f5f7fa, #c3cfe2); margin: 0; padding: 30px; box-sizing: border-box; } .header { padding: 20px 30px; background-color: #333; border-radius: 8px; text-align: center; margin-bottom: 30px; color: #fff; font-size: 24px; } .order-details { background-color: #ffffff; border-radius: 8px; padding: 20px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 20px; } .order-details h4 { font-size: 18px; font-weight: bold; margin-bottom: 15px; } .order-info, .customer-info, .product-info { padding: 10px 0; } .info-label { font-weight: bold; margin-right: 10px; } </style> </head> <body> <div class="header"> Order #<?= htmlspecialchars($order['order_id']) ?> Details </div> <div class="order-details"> <h4>Order Information</h4> <div class="order-info"> <span class="info-label">Status:</span><?= htmlspecialchars($order['status']) ?><br> <span class="info-label">Order Date:</span><?= date("d M Y, h:i A", strtotime($order['order_date'])) ?><br> <span class="info-label">Delivery DateTime:</span><?= $order['delivery_datetime'] ? date("d M Y, h:i A", strtotime($order['delivery_datetime'])) : 'N/A' ?><br> </div> <h4>Customer Information</h4> <div class="customer-info"> <span class="info-label">Name:</span><?= htmlspecialchars($order['customer_name']) ?><br> <span class="info-label">Contact:</span><?= htmlspecialchars($order['contact']) ?><br> <span class="info-label">Delivery Address:</span><?= nl2br(htmlspecialchars($order['delivery_address'])) ?><br> </div> <h4>Primary Product Information</h4> <div class="product-info"> <span class="info-label">Product:</span><?= htmlspecialchars($order['primary_product_name'] . " - " . $order['primary_product_size']) ?><br> <span class="info-label">Quantity:</span><?= htmlspecialchars($order['primary_quantity']) ?><br> <span class="info-label">Packaging:</span><?= htmlspecialchars($order['primary_packaging_preferences']) ?><br> </div> <h4>Additional Products</h4> <div class="product-info"> <?php if (!empty($order_items)): ?> <?php foreach ($order_items as $item): ?> <span class="info-label">Product:</span><?= htmlspecialchars($item['product_name'] . " - " . $item['product_size']) ?><br> <span class="info-label">Quantity:</span><?= htmlspecialchars($item['quantity']) ?><br> <span class="info-label">Packaging:</span><?= htmlspecialchars($item['packaging_preferences']) ?><br><br> <?php endforeach; ?> <?php else: ?> <p>No additional products.</p> <?php endif; ?> </div> </div> <a href="view_orders.php" class="btn btn-secondary">Back to Orders</a> </body> </html>Key Parts of the Implementation
-
Error handling: Check if the
order_idis present and valid. Redirect with an error if the order is not found or an invalid ID is provided. -
Data Fetching: Use SQL queries to get all necessary data:
- Order information such as status, order date, and delivery date.
- Customer-related details for the order.
- Fetch the primary product as well as additional products associated with the order.
-
Output: Present the fetched information in a user-friendly way using HTML and CSS to style the details page.
Step 2: Update Links in
view_orders.phpMake sure there is a link in your
view_orders.phpfile to this new order detail view. Update the actions section to include a view details button:<a href="view_order_customer.php?order_id=<?= htmlspecialchars($order['order_id']) ?>" class="btn btn-sm btn-outline-primary" title="View Details"> <i class="bi bi-eye-fill"></i> </a>Step 3: Manage Errors
Consider adding error management for orders not found and invalid IDs, making sure these codes reflect a comprehensive experience for users.
Make sure the above view displays correctly based on your layout and structure. Ensure paths and includes are correctly aligned with your folder setup.
-