-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_availability.php
More file actions
38 lines (35 loc) · 1.19 KB
/
check_availability.php
File metadata and controls
38 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
require 'staff/db.php';
$available_futsals = [];
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$start_time = $_POST['start_time'] ?? null;
$end_time = $_POST['end_time'] ?? null;
if ($start_time && $end_time) {
try {
$stmt = $pdo->prepare("
SELECT * FROM futsals f
WHERE NOT EXISTS (
SELECT 1 FROM bookings b
WHERE b.futsal_id = f.id
AND (
(b.start_time <= :start_time1 AND b.end_time > :start_time2) OR
(b.start_time < :end_time1 AND b.end_time >= :end_time2)
)
)
");
$stmt->execute([
'start_time1' => $start_time,
'start_time2' => $start_time,
'end_time1' => $end_time,
'end_time2' => $end_time
]);
$available_futsals = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$error_message = "Database Error: " . $e->getMessage();
}
} else {
$error_message = "Please provide both start time and end time.";
}
}
?>