From 77de6ece1cfc5d175976ebc3b8ea5ddcabab83ee Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 18 Jun 2026 14:40:33 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/api.php b/api.php index 67770d3..d564d39 100644 --- a/api.php +++ b/api.php @@ -105,10 +105,25 @@ switch ($action) { case 'delete_film': checkAuth($pdo); - $table = ($_GET['type'] === 'videotheque') ? 'videotheque' : 'critiques'; + $type = $_GET['type'] ?? 'critique'; + $table = ($type === 'videotheque') ? 'videotheque' : 'critiques'; + $id = $_GET['id'] ?? null; + + if (!$id) { + http_response_code(400); + echo json_encode(["error" => "ID manquant."]); + break; + } + $stmt = $pdo->prepare("DELETE FROM $table WHERE id = ?"); - $stmt->execute([$_GET['id']]); - echo json_encode(["success" => true]); + $stmt->execute([$id]); + + if ($stmt->rowCount() === 0) { + http_response_code(404); + echo json_encode(["error" => "Aucun enregistrement trouvé avec cet ID."]); + } else { + echo json_encode(["success" => true]); + } break; case 'bulk_delete':