<?php
include 'db.php';

// Get form data
$table_id = $_POST['table_id'];
$floor_id = $_POST['floor_id'];
$table_name = $_POST['table_name'];
$seats = $_POST['seats'] ?: 4;
$status = $_POST['status'];

// Validate input
if (empty($table_id) || empty($floor_id) || empty($table_name)) {
    header("Location: table_list.php?error=missing_data");
    exit;
}

// Update the table
$sql = "UPDATE dinein_tables SET 
        floor_id = ?, 
        table_name = ?, 
        seats = ?, 
        status = ? 
        WHERE id = ?";

$stmt = $conn->prepare($sql);
$stmt->bind_param("isisi", $floor_id, $table_name, $seats, $status, $table_id);

if ($stmt->execute()) {
    header("Location: table_list.php?success=updated");
} else {
    header("Location: table_list.php?error=update_failed");
}

$stmt->close();
?>
