From 27ba709f02408715f62bdc42dc354fb2d584daab Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 18 Jun 2026 16:55:28 +0200 Subject: [PATCH] Actualiser api.php --- api.php | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/api.php b/api.php index 5428c31..cf7fc74 100644 --- a/api.php +++ b/api.php @@ -143,22 +143,28 @@ switch ($action) { echo json_encode(["success" => true]); break; - case 'delete_film': - checkAuth($pdo); - $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([$id]); - echo json_encode(["success" => true]); +case 'delete_film': + checkAuth($pdo); + $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([$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': checkAuth($pdo);