<?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'] ?? '');
if ($name === '') {
    die("Nom du concurrent obligatoire");
}

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

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

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