<?php
include 'db.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = $_POST['name'];
    $phone = $_POST['phone'] ?? '';
    $email = $_POST['email'] ?? '';
    $address = $_POST['address'] ?? '';
    $ntn = $_POST['ntn'] ?? '';
    $province = $_POST['province'] ?? 'Punjab';
    $active = isset($_POST['active']) ? 1 : 0;
    $category_id = $_POST['category_id'] ?? NULL;
    $is_walk_in = isset($_POST['is_walk_in']) ? 1 : 0;

    $stmt = $conn->prepare("INSERT INTO customers (name, phone, email, address, ntn, province, active, category_id, is_walk_in) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("ssssssiii", $name, $phone, $email, $address, $ntn, $province, $active, $category_id, $is_walk_in);
    $stmt->execute();

    header("Location: customer_list.php?success=1");
    exit;
}
?>
