How can the code be modified to handle cases where the start date of a booking request is before the existing booking start date and the end date is after the existing booking end date?

When the start date of a booking request is before the existing booking start date and the end date is after the existing booking end date, the code needs to handle this by splitting the existing booking into two separate bookings: one before the requested booking and one after. This can be achieved by updating the end date of the existing booking to the start date of the requested booking, creating a new booking for the requested period, and updating the start date of the existing booking to the end date of the requested booking.

// Check if the start date of the booking request is before the existing booking start date
if ($booking_start < $existing_booking_start) {
    // Split the existing booking into two separate bookings
    $existing_booking_end = $booking_start; // Update end date of existing booking
    // Create a new booking for the requested period
    $new_booking_start = $booking_start;
    $new_booking_end = $booking_end;
    // Update the start date of the existing booking
    $existing_booking_start = $booking_end;
    
    // Save the updated existing booking and the new booking to the database
    // Update existing booking query
    // Insert new booking query
}