please fix this codes (<?php
// Include authentication, database connection, and functions
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php';

// Initialize variables for messages
$errors = [];
$success = "";

// Handle Form Submissions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Handle Add New Driver
    if (isset($_POST['add_driver'])) {
        $name = trim($_POST['name']);
        $number = trim($_POST['number']);

        // Basic validation
        if (empty($name) || empty($number)) {
            $errors[] = "Driver name and number are required.";
        } else {
            // Insert into database using prepared statements to prevent SQL injection
            $stmt = $conn->prepare("INSERT INTO drivers (name, number) VALUES (?, ?)");
            if ($stmt) {
                $stmt->bind_param("ss", $name, $number);
                if ($stmt->execute()) {
                    $success = "New driver added successfully.";
                } else {
                    $errors[] = "Error adding driver: " . htmlspecialchars($stmt->error, ENT_QUOTES, 'UTF-8');
                }
                $stmt->close();
            } else {
                $errors[] = "Database error: Unable to prepare statement.";
            }
        }
    }

    // Handle Delete Driver
    if (isset($_POST['delete_driver'])) {
        $driver_id = intval($_POST['id']);
        if ($driver_id > 0) {
            // Delete driver using prepared statements
            $stmt = $conn->prepare("DELETE FROM drivers WHERE id = ?");
            if ($stmt) {
                $stmt->bind_param("i", $driver_id);
                if ($stmt->execute()) {
                    $success = "Driver deleted successfully.";
                } else {
                    $errors[] = "Error deleting driver: " . htmlspecialchars($stmt->error, ENT_QUOTES, 'UTF-8');
                }
                $stmt->close();
            } else {
                $errors[] = "Database error: Unable to prepare statement.";
            }
        } else {
            $errors[] = "Invalid driver ID.";
        }
    }

    // Handle Toggle Star Status
    if (isset($_POST['toggle_star'])) {
        $driver_id = intval($_POST['id']);
        $new_star_status = intval($_POST['is_star']); // Expected 0 or 1

        if ($driver_id > 0 && in_array($new_star_status, [0, 1])) {
            $stmt = $conn->prepare("UPDATE drivers SET is_star = ? WHERE id = ?");
            if ($stmt) {
                $stmt->bind_param("ii", $new_star_status, $driver_id);
                if ($stmt->execute()) {
                    $status = $new_star_status ? 'starred as important' : 'unstarred';
                    $success = "Driver successfully $status.";
                } else {
                    $errors[] = "Error updating star status: " . htmlspecialchars($stmt->error, ENT_QUOTES, 'UTF-8');
                }
                $stmt->close();
            } else {
                $errors[] = "Database error: Unable to prepare statement.";
            }
        } else {
            $errors[] = "Invalid driver ID or star status.";
        }
    }
}

// Function to format phone numbers for WhatsApp links
function formatPhoneNumberForWhatsApp($number)
{
    // Strip out non-numeric characters
    return preg_replace('/\D/', '', $number);
}

// Fetch drivers from the database with optional search and sorting
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
$filter_star = isset($_GET['filter_star']) ? intval($_GET['filter_star']) : 0; // 1 to filter starred drivers
$sort = isset($_GET['sort']) ? trim($_GET['sort']) : 'star_desc';

// Determine sorting order
switch ($sort) {
    case 'name_asc':
        $order_by = 'name ASC';
        break;
    case 'name_desc':
        $order_by = 'name DESC';
        break;
    case 'number_asc':
        $order_by = 'number ASC';
        break;
    case 'number_desc':
        $order_by = 'number DESC';
        break;
    case 'star_asc':
        $order_by = 'is_star ASC, name ASC'; // Non-starred first
        break;
    case 'star_desc':
    default:
        $order_by = 'is_star DESC, name ASC'; // Starred first
}

// Prepare the SQL statement
if (!empty($search)) {
    // Use prepared statements to prevent SQL injection
    $stmt = $conn->prepare("SELECT * FROM drivers WHERE name LIKE ? OR number LIKE ? " . ($filter_star ? "AND is_star = 1 " : "") . "ORDER BY $order_by");
    if ($stmt) {
        $like_search = '%' . $search . '%';
        $stmt->bind_param("ss", $like_search, $like_search);
    } else {
        die('Database error: ' . htmlspecialchars(mysqli_error($conn), ENT_QUOTES, 'UTF-8'));
    }
} else {
    $stmt = $conn->prepare("SELECT * FROM drivers " . ($filter_star ? "WHERE is_star = 1 " : "") . "ORDER BY $order_by");
    if (!$stmt) {
        die('Database error: ' . htmlspecialchars(mysqli_error($conn), ENT_QUOTES, 'UTF-8'));
    }
}

// Execute the statement and fetch results
$stmt->execute();
$result = $stmt->get_result();
if (!$result) {
    die('Query failed: ' . htmlspecialchars(mysqli_error($conn), ENT_QUOTES, 'UTF-8'));
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Drivers List</title>
    <!-- Tailwind CSS CDN -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- Font Awesome for Icons -->
    <script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
    <!-- Custom Styles -->
    <style>
        /* Custom Modal Styles */
        .modal {
            display: none;
            /* Hidden by default */
            position: fixed;
            /* Stay in place */
            z-index: 50;
            /* Sit on top */
            left: 0;
            top: 0;
            width: 100%;
            /* Full width */
            height: 100%;
            /* Full height */
            overflow: auto;
            /* Enable scroll if needed */
            background-color: rgba(0, 0, 0, 0.5);
            /* Black w/ opacity */
        }

        .modal-content {
            background-color: white;
            margin: 5%;
            /* 5% from the top and centered */
            padding: 20px;
            border: 1px solid #888;
            width: 90%;
            max-width: 500px;
            /* Could be more or less, depending on screen size */
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .close {
            color: #aaa;
            float: right;
            font-size: 1.5rem;
            font-weight: bold;
            cursor: pointer;
        }

        .close:hover,
        .close:focus {
            color: black;
        }

        /* Tooltip Styles */
        .tooltip {
            position: relative;
            display: inline-block;
        }

        .tooltip .tooltiptext {
            visibility: hidden;
            width: 120px;
            background-color: #333;
            color: #fff;
            text-align: center;
            border-radius: 6px;
            padding: 5px 0;

            /* Position the tooltip */
            position: absolute;
            z-index: 1;
            bottom: 125%;
            left: 50%;
            margin-left: -60px;

            /* Fade in tooltip */
            opacity: 0;
            transition: opacity 0.3s;
        }

        .tooltip:hover .tooltiptext {
            visibility: visible;
            opacity: 1;
        }

        /* Floating Action Button (FAB) */
        .fab {
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 100;
        }
    </style>
</head>

<body class="bg-gray-100 min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <!-- Header Section -->
        <div class="flex flex-col md:flex-row items-center justify-between mb-6">
            <h2 class="text-3xl font-bold text-gray-800">Drivers List</h2>
            <div class="flex items-center space-x-4 mt-4 md:mt-0">
                <button id="toggleStarred" class="bg-yellow-400 text-gray-800 px-4 py-2 rounded-md shadow hover:bg-yellow-300 transition">
                    <?php if ($filter_star): ?>
                        <i class="fas fa-star"></i> Show All
                    <?php else: ?>
                        <i class="far fa-star"></i> Show Starred
                    <?php endif; ?>
                </button>
                <!-- You can add more buttons or filters here -->
            </div>
        </div>

        <!-- Filter and Search Section -->
        <div class="flex flex-col md:flex-row items-center justify-between mb-6">
            <form method="GET" action="drivers_list.php" id="searchForm" class="flex flex-col md:flex-row items-center w-full md:w-auto space-y-4 md:space-y-0">
                <div class="flex items-center border border-gray-300 rounded-md overflow-hidden">
                    <input type="text" name="search" id="searchInput" placeholder="Search by name or number..." value="<?= htmlspecialchars($search, ENT_QUOTES, 'UTF-8') ?>" class="w-full px-4 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
                <div class="flex items-center space-x-4">
                    <select name="sort" id="sortSelect" onchange="this.form.submit()" class="px-4 py-2 border border-gray-300 bg-white rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
                        <option value="star_desc" <?= ($sort === 'star_desc') ? 'selected' : '' ?>>Starred First</option>
                        <option value="star_asc" <?= ($sort === 'star_asc') ? 'selected' : '' ?>>Starred Last</option>
                        <option value="name_asc" <?= ($sort === 'name_asc') ? 'selected' : '' ?>>Sort by Name (A-Z)</option>
                        <option value="name_desc" <?= ($sort === 'name_desc') ? 'selected' : '' ?>>Sort by Name (Z-A)</option>
                        <option value="number_asc" <?= ($sort === 'number_asc') ? 'selected' : '' ?>>Sort by Number (Ascending)</option>
                        <option value="number_desc" <?= ($sort === 'number_desc') ? 'selected' : '' ?>>Sort by Number (Descending)</option>
                        <option value="recent_desc" <?= ($sort === 'recent_desc') ? 'selected' : '' ?>>Recently Added</option>
                        <option value="recent_asc" <?= ($sort === 'recent_asc') ? 'selected' : '' ?>>Oldest Added</option>
                    </select>
                    <button type="submit" class="bg-gray-500 text-white px-4 py-2 rounded-md hover:bg-gray-600 transition">Search</button>
                </div>
            </form>
        </div>

        <!-- Success and Error Messages -->
        <?php if (!empty($success)): ?>
            <div class="mb-4 bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative" role="alert">
                <span class="block sm:inline"><?= htmlspecialchars($success, ENT_QUOTES, 'UTF-8') ?></span>
                <span class="absolute top-0 bottom-0 right-0 px-4 py-3">
                    <svg class="fill-current h-6 w-6 text-green-500" role="button" xmlns="http://www.w3.org/2000/svg"
                        viewBox="0 0 20 20">
                        <title>Close</title>
                        <path
                            d="M14.348 5.652a1 1 0 00-1.414 0L10 8.586 7.066 5.652a1 1 0 10-1.414 1.414L8.586 10l-2.934 2.934a1 1 0 101.414 1.414L10 11.414l2.934 2.934a1 1 0 001.414-1.414L11.414 10l2.934-2.934a1 1 0 000-1.414z" />
                    </svg>
                </span>
            </div>
        <?php endif; ?>

        <?php if (!empty($errors)): ?>
            <div class="mb-4 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
                <ul class="list-disc pl-5">
                    <?php foreach ($errors as $error): ?>
                        <li><?= htmlspecialchars($error, ENT_QUOTES, 'UTF-8') ?></li>
                    <?php endforeach; ?>
                </ul>
                <span class="absolute top-0 bottom-0 right-0 px-4 py-3">
                    <svg class="fill-current h-6 w-6 text-red-500" role="button" xmlns="http://www.w3.org/2000/svg"
                        viewBox="0 0 20 20">
                        <title>Close</title>
                        <path
                            d="M14.348 5.652a1 1 0 00-1.414 0L10 8.586 7.066 5.652a1 1 0 10-1.414 1.414L8.586 10l-2.934 2.934a1 1 0 101.414 1.414L10 11.414l2.934 2.934a1 1 0 001.414-1.414L11.414 10l2.934-2.934a1 1 0 000-1.414z" />
                    </svg>
                </span>
            </div>
        <?php endif; ?>

        <!-- Drivers Grid -->
        <div id="driversGrid" class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
            <?php if ($result->num_rows > 0): ?>
                <?php while ($row = $result->fetch_assoc()): ?>
                    <div class="bg-white rounded-lg shadow-md p-6 flex flex-col justify-between transform transition-transform hover:scale-105">
                        <div>
                            <h3 class="text-xl font-semibold text-gray-800 mb-2 flex items-center">
                                <?= htmlspecialchars($row['name'], ENT_QUOTES, 'UTF-8') ?>
                                <!-- Star Icon with Tooltip -->
                                <div class="tooltip ml-2">
                                    <form action="drivers_list.php" method="POST" class="inline">
                                        <input type="hidden" name="id" value="<?= htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8') ?>">
                                        <input type="hidden" name="is_star" value="<?= $row['is_star'] ? 0 : 1; ?>">
                                        <button type="submit" name="toggle_star" class="focus:outline-none">
                                            <?php if ($row['is_star']): ?>
                                                <i class="fas fa-star text-yellow-500 text-lg"></i>
                                            <?php else: ?>
                                                <i class="far fa-star text-gray-400 text-lg hover:text-yellow-500 transition-colors"></i>
                                            <?php endif; ?>
                                        </button>
                                        <span class="tooltiptext">Click to Favorite</span>
                                    </form>
                                </div>
                            </h3>
                            <p class="text-gray-600 mb-4 flex items-center">
                                <i class="fas fa-phone-alt mr-2 text-indigo-500"></i><?= htmlspecialchars($row['number'], ENT_QUOTES, 'UTF-8') ?>
                            </p>
                        </div>
                        <div class="mt-4 flex justify-between items-center">
                            <a href="https://wa.me/<?= formatPhoneNumberForWhatsApp($row['number']); ?>" target="_blank"
                                class="bg-gradient-to-r from-green-400 to-green-600 text-white px-3 py-2 rounded-md flex items-center hover:from-green-500 hover:to-green-700 transition">
                                <i class="fab fa-whatsapp mr-2"></i> WhatsApp
                            </a>
                            <div class="flex space-x-2 items-center">
                                <a href="edit_driver.php?id=<?= htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8'); ?>"
                                    class="bg-gradient-to-r from-blue-400 to-blue-600 text-white px-3 py-2 rounded-md flex items-center hover:from-blue-500 hover:to-blue-700 transition">
                                    <i class="fas fa-edit mr-2"></i> Edit
                                </a>
                                <form action="delete_driver.php" method="POST" onsubmit="return confirm('Are you sure you want to delete this driver?');"
                                    class="inline">
                                    <input type="hidden" name="id" value="<?= htmlspecialchars($row['id'], ENT_QUOTES, 'UTF-8'); ?>">
                                    <button type="submit" name="delete_driver"
                                        class="bg-gradient-to-r from-red-400 to-red-600 text-white px-3 py-2 rounded-md flex items-center hover:from-red-500 hover:to-red-700 transition">
                                        <i class="fas fa-trash-alt mr-2"></i> Delete
                                    </button>
                                </form>
                            </div>
                        </div>
                    </div>
                <?php endwhile; ?>
            <?php else: ?>
                <p class="col-span-full text-center text-gray-600">No drivers found.</p>
            <?php endif; ?>
        </div>

        <!-- Floating Action Button (FAB) for Adding New Driver -->
        <div class="fab">
            <button id="addDriverFab" class="bg-indigo-600 text-white rounded-full h-16 w-16 flex items-center justify-center shadow-lg hover:bg-indigo-700 transition">
                <i class="fas fa-plus text-2xl"></i>
            </button>
        </div>

        <!-- Add Driver Modal -->
        <div id="addDriverModal" class="modal">
            <div class="modal-content">
                <span class="close" id="closeModal">&times;</span>
                <h2 class="text-2xl font-bold mb-4 text-gray-800">Add New Driver</h2>
                <form action="drivers_list.php" method="POST">
                    <div class="mb-4">
                        <label for="name" class="block text-gray-700">Driver Name</label>
                        <input type="text" id="name" name="name" required
                            class="w-full mt-1 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div class="mb-6">
                        <label for="number" class="block text-gray-700">Driver Number</label>
                        <input type="text" id="number" name="number" required placeholder="+1234567890"
                            class="w-full mt-1 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
                    </div>
                    <div class="flex justify-end">
                        <button type="button" id="cancelBtn" class="bg-gray-500 text-white px-4 py-2 rounded-md mr-2 hover:bg-gray-600">Cancel</button>
                        <button type="submit" name="add_driver"
                            class="bg-indigo-600 text-white px-4 py-2 rounded-md hover:bg-indigo-700">Add Driver</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Include the footer -->
    <?php
    require_once '../../includes/footer.php';
    ?>

    <!-- JavaScript for Modal Functionality and Real-Time Search -->
    <script>
        // Modal Elements
        const modal = document.getElementById("addDriverModal");
        const addDriverBtn = document.getElementById("addDriverBtn");
        const addDriverFab = document.getElementById("addDriverFab");
        const closeModal = document.getElementById("closeModal");
        const cancelBtn = document.getElementById("cancelBtn");

        // Open the modal when the user clicks the Add Driver button or FAB
        addDriverBtn.onclick = function () {
            modal.style.display = "block";
        }
        addDriverFab.onclick = function () {
            modal.style.display = "block";
        }

        // Close the modal when the user clicks on <span> (x)
        closeModal.onclick = function () {
            modal.style.display = "none";
        }

        // Close the modal when the user clicks on Cancel button
        cancelBtn.onclick = function () {
            modal.style.display = "none";
        }

        // Close the modal when the user clicks anywhere outside of the modal
        window.onclick = function (event) {
            if (event.target == modal) {
                modal.style.display = "none";
            }
        }

        // Real-Time Search Functionality
        const searchInput = document.getElementById('searchInput');
        const driversGrid = document.getElementById('driversGrid');
        const toggleStarredBtn = document.getElementById('toggleStarred');

        searchInput.addEventListener('input', function () {
            document.getElementById('searchForm').submit();
        });

        // Toggle Starred Drivers Filter
        toggleStarredBtn.addEventListener('click', function () {
            const currentURL = new URL(window.location.href);
            const filterStar = currentURL.searchParams.get('filter_star') === '1' ? 0 : 1;
            currentURL.searchParams.set('filter_star', filterStar);
            window.location.href = currentURL.toString();
        });
    </script>
</body>

</html>) add add driver button instead of circle and change the deigsn and make it cool deisgn and add star in the box changeable, when i selected it will be important and has star and type full codes, and make it flexible user experience and this edit driver (<?php
// edit_driver.php

// Include authentication, database connection, and functions
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';
require_once __DIR__ . '/../../includes/functions.php';

// Initialize variables
$driver_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$name = '';
$number = '';
$error = '';
$success = '';

// Fetch existing driver details
if ($driver_id > 0) {
    $stmt = $conn->prepare("SELECT * FROM drivers WHERE id = ?");
    if ($stmt) {
        $stmt->bind_param("i", $driver_id);
        $stmt->execute();
        $result = $stmt->get_result();
        if ($result->num_rows === 1) {
            $driver = $result->fetch_assoc();
            $name = $driver['name'];
            $number = $driver['number'];
        } else {
            $error = "Driver not found.";
        }
        $stmt->close();
    } else {
        $error = "Database error: Unable to prepare statement.";
    }
} else {
    $error = "Invalid Driver ID.";
}

// Handle form submission for editing driver
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_driver'])) {
    $name = trim($_POST['name']);
    $number = trim($_POST['number']);

    // Basic validation
    if (empty($name) || empty($number)) {
        $error = "Driver name and number are required.";
    } else {
        // Update the driver in the database using prepared statements
        $stmt = $conn->prepare("UPDATE drivers SET name = ?, number = ? WHERE id = ?");
        if ($stmt) {
            $stmt->bind_param("ssi", $name, $number, $driver_id);
            if ($stmt->execute()) {
                $success = "Driver updated successfully.";
            } else {
                $error = "Error updating driver: " . htmlspecialchars($stmt->error, ENT_QUOTES, 'UTF-8');
            }
            $stmt->close();
        } else {
            $error = "Database error: Unable to prepare statement.";
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Edit Driver</title>
    <!-- Tailwind CSS CDN -->
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- Font Awesome for Icons -->
    <script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
    <!-- Custom Styles -->
    <style>
        /* Custom Modal Styles */
        .modal {
            display: none;
            /* Hidden by default */
            position: fixed;
            /* Stay in place */
            z-index: 50;
            /* Sit on top */
            left: 0;
            top: 0;
            width: 100%;
            /* Full width */
            height: 100%;
            /* Full height */
            overflow: auto;
            /* Enable scroll if needed */
            background-color: rgba(0, 0, 0, 0.5);
            /* Black w/ opacity */
        }

        .modal-content {
            background-color: white;
            margin: 5%;
            /* 5% from the top and centered */
            padding: 20px;
            border: 1px solid #888;
            width: 90%;
            max-width: 500px;
            /* Could be more or less, depending on screen size */
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        .close {
            color: #aaa;
            float: right;
            font-size: 1.5rem;
            font-weight: bold;
            cursor: pointer;
        }

        .close:hover,
        .close:focus {
            color: black;
        }
    </style>
</head>

<body class="bg-gray-100 min-h-screen flex items-center justify-center">
    <div class="bg-white p-8 rounded-lg shadow-lg w-full max-w-lg">
        <div class="flex justify-between items-center mb-4">
            <h2 class="text-2xl font-bold">Edit Driver</h2>
            <a href="drivers_list.php" class="text-gray-500 hover:text-gray-700"><i class="fas fa-times"></i></a>
        </div>

        <!-- Display Success or Error Messages -->
        <?php if (!empty($success)): ?>
            <div class="mb-4 bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative" role="alert">
                <span class="block sm:inline"><?= htmlspecialchars($success, ENT_QUOTES, 'UTF-8') ?></span>
            </div>
        <?php endif; ?>

        <?php if (!empty($error)): ?>
            <div class="mb-4 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert">
                <span class="block sm:inline"><?= htmlspecialchars($error, ENT_QUOTES, 'UTF-8') ?></span>
            </div>
        <?php endif; ?>

        <?php if ($driver_id > 0 && empty($error)): ?>
            <form action="edit_driver.php?id=<?= htmlspecialchars($driver_id, ENT_QUOTES, 'UTF-8'); ?>" method="POST">
                <div class="mb-4">
                    <label for="name" class="block text-gray-700">Driver Name</label>
                    <input type="text" id="name" name="name" value="<?= htmlspecialchars($name, ENT_QUOTES, 'UTF-8'); ?>" required
                        class="w-full mt-1 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
                <div class="mb-6">
                    <label for="number" class="block text-gray-700">Driver Number</label>
                    <input type="text" id="number" name="number" value="<?= htmlspecialchars($number, ENT_QUOTES, 'UTF-8'); ?>" required placeholder="+1234567890"
                        class="w-full mt-1 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500">
                </div>
                <div class="flex justify-end">
                    <button type="submit" name="edit_driver"
                        class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700">Update Driver</button>
                </div>
            </form>
        <?php else: ?>
            <div class="text-center">
                <a href="drivers_list.php" class="text-indigo-600 hover:text-indigo-800">Back to Drivers List</a>
            </div>
        <?php endif; ?>
    </div>
</body>

</html>) and delete driver (<?php
// delete_driver.php

// Include authentication and database connection
require_once __DIR__ . '/../../includes/auth.php';
require_once __DIR__ . '/../../includes/db_connect.php';

// Start session to store messages
session_start();

// Check if the request method is POST
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Validate and sanitize driver ID
    if (isset($_POST['id']) && filter_var($_POST['id'], FILTER_VALIDATE_INT)) {
        $driver_id = $_POST['id'];

        // Delete driver using prepared statements
        $stmt = $conn->prepare("DELETE FROM drivers WHERE id = ?");
        if ($stmt) {
            $stmt->bind_param("i", $driver_id);

            if ($stmt->execute()) {
                $_SESSION['success'] = "Driver deleted successfully.";
            } else {
                $_SESSION['error'] = "Error deleting driver: " . htmlspecialchars($stmt->error, ENT_QUOTES, 'UTF-8');
            }
            $stmt->close();
        } else {
            $_SESSION['error'] = "Database error: Unable to prepare statement.";
        }
    } else {
        $_SESSION['error'] = "Invalid driver ID.";
    }

    // Redirect back to drivers list
    header("Location: drivers_list.php");
    exit();
} else {
    // If accessed without POST, redirect back
    header("Location: drivers_list.php");
    exit();
}
?>) and this info database (-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Nov 10, 2024 at 10:01 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 `ads`
--

CREATE TABLE `ads` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `ad_type` enum('Post','Story') NOT NULL,
  `related_id` int(11) NOT NULL,
  `budget` decimal(10,2) NOT NULL,
  `total_spent` decimal(10,2) DEFAULT 0.00,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `status` enum('Active','Paused','Completed') DEFAULT 'Active',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `ad_spend_logs`
--

CREATE TABLE `ad_spend_logs` (
  `id` int(11) NOT NULL,
  `ad_id` int(11) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `spend_date` datetime DEFAULT current_timestamp(),
  `description` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- 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 `drivers`
--

CREATE TABLE `drivers` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `number` varchar(15) NOT NULL,
  `is_star` tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `notifications`
--

CREATE TABLE `notifications` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `type` enum('order','post','plan','note') NOT NULL,
  `message` varchar(255) NOT NULL,
  `link` varchar(255) NOT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) 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,
  `status` enum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',
  `priority` enum('Normal','Important','Quick') DEFAULT 'Normal',
  `order_date` datetime DEFAULT current_timestamp(),
  `delivery_datetime` datetime DEFAULT NULL,
  `delivery_date` date 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 DEFAULT 1,
  `packaging_preferences` varchar(255) DEFAULT NULL,
  `discount_percentage` decimal(5,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,
  `name` varchar(100) NOT NULL,
  `size` varchar(50) DEFAULT NULL,
  `price` decimal(10,2) NOT NULL,
  `category` varchar(50) DEFAULT NULL,
  `thumbnail` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `email` varchar(100) DEFAULT NULL,
  `password` varchar(255) NOT NULL,
  `role` enum('admin','staff') NOT NULL,
  `profile_image` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `workspace_notes`
--

CREATE TABLE `workspace_notes` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `content` text NOT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `workspace_plans`
--

CREATE TABLE `workspace_plans` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `due_date` datetime DEFAULT NULL,
  `status` enum('Not Started','In Progress','Completed') DEFAULT 'Not Started',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Table structure for table `workspace_posts`
--

CREATE TABLE `workspace_posts` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `platform` enum('Instagram','Facebook','Twitter','Other') NOT NULL,
  `content` text NOT NULL,
  `media_url` varchar(255) DEFAULT NULL,
  `scheduled_datetime` datetime DEFAULT NULL,
  `status` enum('Scheduled','Posted','Failed') DEFAULT 'Scheduled',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `type` enum('Post','Story') DEFAULT 'Post'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `ads`
--
ALTER TABLE `ads`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `related_id` (`related_id`);

--
-- Indexes for table `ad_spend_logs`
--
ALTER TABLE `ad_spend_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `ad_id` (`ad_id`);

--
-- Indexes for table `customers`
--
ALTER TABLE `customers`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `drivers`
--
ALTER TABLE `drivers`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `notifications`
--
ALTER TABLE `notifications`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `created_at` (`created_at`);

--
-- Indexes for table `orders`
--
ALTER TABLE `orders`
  ADD PRIMARY KEY (`id`),
  ADD KEY `customer_id` (`customer_id`),
  ADD KEY `idx_orders_customer_id` (`customer_id`);

--
-- Indexes for table `order_items`
--
ALTER TABLE `order_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `order_id` (`order_id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `idx_order_items_order_id` (`order_id`),
  ADD KEY `idx_order_items_product_id` (`product_id`);

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`);

--
-- Indexes for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `ads`
--
ALTER TABLE `ads`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `ad_spend_logs`
--
ALTER TABLE `ad_spend_logs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `customers`
--
ALTER TABLE `customers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `drivers`
--
ALTER TABLE `drivers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `notifications`
--
ALTER TABLE `notifications`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `orders`
--
ALTER TABLE `orders`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `order_items`
--
ALTER TABLE `order_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `ads`
--
ALTER TABLE `ads`
  ADD CONSTRAINT `fk_ads_related_id` FOREIGN KEY (`related_id`) REFERENCES `workspace_posts` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_ads_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `ad_spend_logs`
--
ALTER TABLE `ad_spend_logs`
  ADD CONSTRAINT `fk_ad_spend_logs_ad_id` FOREIGN KEY (`ad_id`) REFERENCES `ads` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `notifications`
--
ALTER TABLE `notifications`
  ADD CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `orders`
--
ALTER TABLE `orders`
  ADD CONSTRAINT `fk_orders_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `order_items`
--
ALTER TABLE `order_items`
  ADD CONSTRAINT `fk_order_items_order_id` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_order_items_product_id` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  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;

--
-- Constraints for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  ADD CONSTRAINT `fk_workspace_notes_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  ADD CONSTRAINT `fk_workspace_plans_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  ADD CONSTRAINT `fk_workspace_posts_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`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 */;) os type full codes and add more codes to make it great and type fll codes