Files
2025-11-01 18:24:35 +01:00

80 lines
1.8 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'php/pdo.php';
if ( !isset($_GET['id']) || !ctype_digit($_GET['id']) ) {
die("Erreur : ID invalide.");
}
$id_article = $_GET['id'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id']) && $_POST['id'] == $id_article) {
$sql = "DELETE FROM articles WHERE id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$id_article]);
header('Location: dashboard.php');
exit;
}
}
try {
$sql_select = "SELECT titre FROM articles WHERE id = ?";
$stmt_select = $pdo->prepare($sql_select);
$stmt_select->execute([$id_article]);
$article = $stmt_select->fetch(PDO::FETCH_ASSOC);
if ($article === false) {
die("Erreur : Cet article n'existe pas.");
}
} catch (PDOException $e) {
die("Erreur : " . $e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Supprimer l'article - Admin</title>
</head>
<body>
<header>
<h1>Confirmer la suppression</h1>
<p>
<a href="dashboard.php">← Annuler et Retourner au Tableau de Bord</a>
</p>
</header>
<hr>
<main>
<p>Voulez-vous vraiment supprimer l'article suivant ?</p>
<h2><?php print htmlspecialchars($article['titre']); ?></h2>
<p>Cette action est irréversible.</p>
<form action="supp.php?id=<?php print $id_article; ?>" method="POST">
<input type="hidden" name="id" value="<?php print $id_article; ?>">
<button type="submit">
OUI
</button>
</form>
<br>
<button type="submit">
<a href="dashboard.php">NON</a>
</button>
</main>
</body>
</html>