
<!--// session_start();-->

<!--// // Get the selected date and time from the POST request-->
<!--// $date = $_POST['date'];-->
<!--// $time = $_POST['time'];-->

<!--// // Check if the slot is already booked-->
<!--// if (isset($_SESSION['booked_slots'][$date][$time])) {-->
<!--//     // Slot is not available-->
<!--//     echo 'not available';-->
<!--// } else {-->
<!--//     // Slot is available-->
<!--//     echo 'available';-->
<!--// }-->

<!--// // Close the session-->
<!--// session_write_close();-->
<?php
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Retrieve form data
    $name = $_POST["name"];
    $email = $_POST["email"];
    $booking_date = $_POST["booking_date"];
    $booking_time = $_POST["booking_time"];

    // Validate form data (you can add more validation as needed)
    if (empty($name) || empty($email) || empty($booking_date) || empty($booking_time)) {
        echo "All fields are required";
    } else {
        // Connect to your database (replace dbname, username, password with your actual database credentials)
        $conn = new mysqli("localhost", "username", "password", "dbname");

        // Check connection
        if ($conn->connect_error) {
            die("Connection failed: " . $conn->connect_error);
        }

        // Check if the slot is already booked
        $sql = "SELECT * FROM bookings WHERE booking_date = '$booking_date' AND booking_time = '$booking_time'";
        $result = $conn->query($sql);

        if ($result->num_rows > 0) {
            echo "Sorry, the slot is already booked. Please choose a different time.";
        } else {
            // If the slot is available, insert the booking into the database
            $sql = "INSERT INTO bookings (name, email, booking_date, booking_time) VALUES ('$name', '$email', '$booking_date', '$booking_time')";

            if ($conn->query($sql) === TRUE) {
                echo "Booking successful! We'll see you on $booking_date at $booking_time.";
            } else {
                echo "Error: " . $sql . "<br>" . $conn->error;
            }
        }

        // Close database connection
        $conn->close();
    }
}
?>