<?php
require_once "../config/db.php";

// Only POST allowed
if($_SERVER['REQUEST_METHOD'] !== 'POST'){
    die("Invalid request");
}

$id    = (int) ($_POST['id'] ?? 0);
$name  = trim($_POST['name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');

if(empty($name)){
    die("Name required");
}

// Update query
$stmt = $conn->prepare("
    UPDATE customers 
    SET name=?, email=?, phone=? 
    WHERE id=?
");

$stmt->bind_param("sssi", $name, $email, $phone, $id);

if(!$stmt->execute()){
    die("Update failed: " . $stmt->error);
}

header("Location: ../pages/customers.php");
exit;