first commit
This commit is contained in:
64
admin/supprimer.php
Normal file
64
admin/supprimer.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// Page pour supprimer un article
|
||||
|
||||
|
||||
require '../include/db.php';
|
||||
require '../include/auth.php';
|
||||
requireLogin();
|
||||
|
||||
// Récupération de l'id de l'article depuis l'URL
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
|
||||
// Si l'id n'est pas valide, retour au tableau
|
||||
if ($id <= 0) {
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Récupérer le titre de l'article pour l'afficher
|
||||
$stmt = $pdo->prepare('SELECT id, titre FROM articles WHERE id = :id');
|
||||
$stmt->execute([':id' => $id]);
|
||||
$article = $stmt->fetch();
|
||||
|
||||
|
||||
if (!$article) {
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($_POST['confirm']) && $_POST['confirm'] === 'yes') {
|
||||
|
||||
$d = $pdo->prepare('DELETE FROM articles WHERE id = :id');
|
||||
$d->execute([':id' => $id]);
|
||||
}
|
||||
|
||||
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Supprimer l'article</title>
|
||||
<link rel="stylesheet" href="stylesup.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Supprimer l'article</h1>
|
||||
|
||||
|
||||
<p>Êtes-vous sûr de vouloir supprimer : <strong><?= htmlspecialchars($article['titre']) ?></strong> ?</p>
|
||||
|
||||
|
||||
<form method="post">
|
||||
<button type="submit" name="confirm" value="yes">Oui</button>
|
||||
<a href="board.php">Annuler</a>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user