<?php
$ROOT = dirname(__DIR__, 3);
require_once $ROOT . '/config/config.php';
require_once $ROOT . '/src/lib/session.php';
require_auth();

$pdo = getDbConnection();

$name = trim($_POST['NAME'] ?? '');
$contact = trim($_POST['contact'] ?? '');

if ($name === '') {
    die("Nom du client obligatoire");
}

$stmt = $pdo->prepare("
    INSERT INTO clients (NAME, contact)
    VALUES (:name, :contact)
");
$stmt->execute([
    ':name' => $name,
    ':contact' => $contact
]);

$_SESSION['success_message'] = "✅ Enregistrement réussi !";

// Retour direct à la page précédente
header("Location: ../clients.php");
exit;
