From 8c7f78bb95e18334e56924a07f5006fc05e16767 Mon Sep 17 00:00:00 2001 From: rubisalpha Date: Thu, 30 Oct 2025 11:47:27 +0000 Subject: [PATCH] Ajouter admin/edit.php --- admin/edit.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 admin/edit.php diff --git a/admin/edit.php b/admin/edit.php new file mode 100644 index 0000000..ca4193a --- /dev/null +++ b/admin/edit.php @@ -0,0 +1,42 @@ +prepare('SELECT * FROM articles WHERE id = :id'); +$stmt->execute(['id' => $id]); +$article = $stmt->fetch(); +if (!$article) { header('Location: /admin/dashboard.php'); exit; } +$errors = []; +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (!verify_csrf($_POST['csrf'] ?? '')) { $errors[] = 'Jeton CSRF invalide.'; } + $titre = trim($_POST['titre'] ?? ''); + $contenu = trim($_POST['contenu'] ?? ''); + if (!$titre) $errors[] = 'Le titre est requis.'; + if (!$contenu) $errors[] = 'Le contenu est requis.'; + if (empty($errors)) { + $stmt = $pdo->prepare('UPDATE articles SET titre = :titre, contenu = :contenu WHERE id = :id'); + $stmt->execute(['titre'=>$titre, 'contenu'=>$contenu, 'id'=>$id]); + flash_set('success', 'Article modifié.'); + header('Location: /admin/dashboard.php'); exit; + } +} +$token = csrf_token(); +?> + +Modifier + + +

Modifier l'article #

+ +
+ +
+
+ +
+ +