<?php
header('Content-Type: application/json');
require_once 'config.php';

$name = $_POST['name'] ?? '';
$date = $_POST['date'] ?? '';
$time = $_POST['time'] ?? '';
$guests = $_POST['guests'] ?? '';
$phone = $_POST['phone'] ?? '';
$special = $_POST['special'] ?? '';

if (!$name || !$date || !$time || !$guests || !$phone) {
    echo json_encode(['success' => false, 'message' => 'All required fields must be filled.']);
    exit;
}

$stmt = $conn->prepare("INSERT INTO reservations (name, date, time, guests, phone, special_requests, created_at) VALUES (?, ?, ?, ?, ?, ?, NOW())");
$stmt->bind_param("sssiss", $name, $date, $time, $guests, $phone, $special);
$success = $stmt->execute();
$stmt->close();

echo json_encode(['success' => $success]);
