Skip to content
PHP Logo

How can PHP be utilized to check if a person has already booked a slot in a specific week?

To check if a person has already booked a slot in a specific week using PHP, you can query your database to see if there are any existing bookings for that person within the specified week. You can use SQL to retrieve the booking information and then check if any bookings fall within the week range.

php
// Assuming $personId is the ID of the person and $weekStartDate and $weekEndDate are the start and end dates of the specific week

// Connect to your database
$conn = new mysqli($servername, $username, $password, $dbname);

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

// Query to check if person has already booked a slot in the specific week
$sql = "SELECT * FROM bookings WHERE person_id = $personId AND booking_date BETWEEN '$weekStartDate' AND '$weekEndDate'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "Person has already booked a slot in the specific week";
} else {
    echo "Person has not booked a slot in the specific week";
}

$conn->close();