27 lines
757 B
PHP
27 lines
757 B
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once 'db/config.php';
|
|
|
|
$response = ['status' => 'error', 'message' => 'Invalid request'];
|
|
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
|
if ($data) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO bookings (title, sport, start_time, end_time) VALUES (?, ?, ?, ?)");
|
|
$stmt->execute([
|
|
$data['title'],
|
|
$data['sport'],
|
|
$data['start'],
|
|
$data['end']
|
|
]);
|
|
$response['status'] = 'success';
|
|
$response['message'] = 'Booking created successfully';
|
|
} catch (PDOException $e) {
|
|
$response['message'] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
echo json_encode($response);
|
|
?>
|