-- Host: 127.0.0.1:3306
-- Generation Time: Nov 08, 2024 at 03:05 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 customers
CREATE TABLE customers (
id int(11) NOT NULL,
name varchar(100) NOT NULL,
contact varchar(50) DEFAULT NULL,
delivery_address text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table orders
CREATE TABLE orders (
id int(11) NOT NULL,
customer_id int(11) NOT NULL,
product_id int(11) NOT NULL,
status enum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',
order_date datetime DEFAULT current_timestamp(),
delivery_datetime datetime DEFAULT NULL,
delivery_date date DEFAULT NULL,
quantity int(11) NOT NULL DEFAULT 1,
packaging_preferences varchar(255) DEFAULT NULL,
discount_amount decimal(10,2) DEFAULT 0.00,
discount_reason varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table order_items
CREATE TABLE order_items (
id int(11) NOT NULL,
order_id int(11) NOT NULL,
product_id int(11) NOT NULL,
quantity int(11) NOT NULL,
packaging_preferences varchar(255) DEFAULT NULL,
discount_amount decimal(10,2) DEFAULT 0.00,
discount_reason varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
--
-- Table structure for table products
CREATE TABLE products (
id int(11) NOT NULL,
varchar(100) NOT NULL,
varchar(50) DEFAULT NULL,
decimal(10,2) NOT NULL,
varchar(50) DEFAULT NULL,
varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Assistant
name
size
price
category
thumbnail
--
-- Table structure for table users
CREATE TABLE users (
id int(11) NOT NULL,
username varchar(50) NOT NULL,
password varchar(255) NOT NULL,
role enum('admin','staff') NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE order_items
ADD CONSTRAINT order_items_ibfk_1 FOREIGN KEY (order_id) REFERENCES orders (id) ON DELETE CASCADE,
ADD CONSTRAINT order_items_ibfk_2 FOREIGN KEY (product_id) REFERENCES products (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 update this codes (<?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 before including the header
require_once DIR . '/../../includes/auth.php';
require_once DIR . '/../../includes/db_connect.php';
// Now include the header
require_once '../../includes/header.php';
// Check if order_id is given
orderid=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
ordersql="SELECTorders.idASorderiorder_stmt = conn−>prepare(order_sql);
orderstmt−>bindparamorder_id);
orderstmt−>execute();order_result = orderstmt−>getresulorder = orderresult−>fetchaorder_stmt->close();
if (!$order) {
header("Location: view_orders.php?error=7"); // Order not found
exit();
}
Added order_discount_amount and order_discount_reason to the primary order query.
Displayed these details if order_discount_amount is greater than 0.
Order Items:
Retrieved discount_amount and discount_reason for each order item.
Displayed these details for each item if discount_amount is greater than 0.
Enhanced Styling:
Color Coding:
Header: Dark brown background with white text for prominence.
Sections: White background with subtle shadows for a clean look.
Discount Sections: Light beige background (#ffebcd) to highlight discounts.
Packaging Preferences: Light cyan background (#e0f7fa) to differentiate packaging details.
Typography:
Increased font sizes for better readability.
Used bold fonts for labels to distinguish them from values.
Buttons:
Styled the "Back to Orders" button with appropriate colors, shadows, and hover effects.
Responsive Design:
Ensured that the layout adjusts gracefully on smaller screens using media queries.
Security Enhancements:
All dynamic content is wrapped with htmlspecialchars() to prevent XSS attacks.
Used number_format() for displaying discount amounts, ensuring consistent formatting.
User Experience:
Added icons to buttons using Bootstrap Icons for better visual cues.
Used <hr> to separate multiple order items for clarity.
Improved spacing and alignment for a more organized layout.
Error Handling:
Added checks after preparing SQL statements to handle potential preparation errors gracefully.
Additional Recommendations:
Disable Error Reporting in Production:
Ensure that display_errors is set to 0 in production environments to prevent sensitive information leakage.
Use Prepared Statements Consistently:
This code already uses prepared statements, which is excellent for preventing SQL injection.
Implement User Roles and Permissions:
Ensure that only authorized users can view order details based on their roles (admin, staff).
Optimize Database Queries:
If performance becomes an issue, consider optimizing your queries or adding necessary indexes.
Accessibility Considerations:
Ensure that color contrasts meet accessibility standards.
Consider adding ARIA labels for better screen reader support.
Final Thoughts:
This updated script provides a more comprehensive and visually appealing interface for viewing order details. It ensures that all relevant information, including discounts and packaging preferences, is clearly presented to the user. The enhancements not only improve aesthetics but also contribute to better user experience and security.