From c3418f0fbc033032960188d025bcff3ad1ee8c64 Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 18 Jun 2026 16:51:36 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/api.php b/api.php index 4ce13cd..5428c31 100644 --- a/api.php +++ b/api.php @@ -17,8 +17,7 @@ try { PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); - // NOUVEAU : Création automatique des tables si elles n'existent pas - // Cela évite les erreurs SQL lors de la toute première exécution de l'application + // Création automatique des tables si elles n'existent pas $pdo->exec("CREATE TABLE IF NOT EXISTS users ( id INT PRIMARY KEY, username VARCHAR(50) NOT NULL, @@ -56,7 +55,6 @@ try { exit; } -// CORRECTION : Protection contre les valeurs nulles function makeStableId($title, $year) { $key = strtolower(trim($title ?? '')) . '|' . trim($year ?? ''); return (abs(crc32($key)) % 2000000000) + 100000000; @@ -118,9 +116,7 @@ switch ($action) { case 'save_film': checkAuth($pdo); $type = $data['type'] ?? 'critique'; - $table = ($type === 'videotheque') ? 'videotheque' : 'critiques'; - // CORRECTION : Protection avec `?? ''` sur les champs title et year $id = !empty($data['id']) ? $data['id'] : makeStableId($data['title'] ?? '', $data['year'] ?? '0000'); if ($type === 'critique') { @@ -167,7 +163,6 @@ switch ($action) { case 'bulk_delete': checkAuth($pdo); $ids = $data['ids'] ?? []; - // CORRECTION : Protection sur type pour éviter un warning PHP $type = $data['type'] ?? 'critique'; $table = ($type === 'videotheque') ? 'videotheque' : 'critiques'; @@ -208,4 +203,5 @@ switch ($action) { http_response_code(400); echo json_encode(["error" => "Aucun fichier reçu."]); } - break; \ No newline at end of file + break; +} \ No newline at end of file