<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
   
    // Retrieve data sent via POST
    $date = $_POST["date"];
    

    // Connect to the database
    $conn = new mysqli("localhost", "design24ilogicx_autotherapy", "I[N1.?ZM-YH~", "design24ilogicx_autotherapy");

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

    
   $sql = "SELECT * FROM booking WHERE booking_date = '$date'";
$result = $conn->query($sql);

// Initialize variables to store booking existence and times
$bookingExists = false;
$bookingTimes = array(); // Initialize an array to store booking times

// Check if any bookings exist
if ($result->num_rows > 0) {
    // Set booking existence flag to true
    $bookingExists = true;
    
    // Loop through the result set to fetch all booking times
    while ($row = $result->fetch_assoc()) {
        // Fetch the booking time from each row and add it to the array
        $bookingTimes[] = $row["booking_time"];
    }
}

// Prepare the response data
$response = array(
    "exists" => $bookingExists,
    "times" => $bookingTimes // Use 'times' to store multiple booking times
);

// Send the response as JSON
header('Content-Type: application/json');
echo json_encode($response);
exit;
}




?>