46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
session_start();
|
|
require_once '../includes/db.php';
|
|
require_once '../includes/header.php';
|
|
|
|
if (!isset($_SESSION['user'])) {
|
|
header("Location: login.php");
|
|
exit;
|
|
}
|
|
|
|
$id = $_GET['id'] ?? null;
|
|
if (!$id || !is_numeric($id)) {
|
|
echo "<p>Article introuvable (404)</p>";
|
|
require_once '../includes/footer.php';
|
|
exit;
|
|
}
|
|
|
|
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
$article = $stmt->fetch();
|
|
|
|
if (!$article) {
|
|
echo "<p>Article introuvable (404)</p>";
|
|
require_once '../includes/footer.php';
|
|
exit;
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$stmt = $pdo->prepare("DELETE FROM articles WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
echo "<p>Article supprimé avec succès.</p>";
|
|
echo '<a href="admin.php">Retour au tableau de bord</a>';
|
|
require_once '../includes/footer.php';
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<h2>Supprimer l'article</h2>
|
|
<p>Êtes-vous sûr de vouloir supprimer l'article "<strong><?= htmlspecialchars($article['titre']) ?></strong>" ?</p>
|
|
<form method="post">
|
|
<input type="submit" value="Oui, supprimer">
|
|
<a href="admin.php">Annuler</a>
|
|
</form>
|
|
|
|
<?php require_once '../includes/footer.php'; ?>
|