61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
session_start();
|
|
require '../includes/db.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$message = '';
|
|
$article = null;
|
|
|
|
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
|
|
$id = $_GET['id'];
|
|
|
|
$sql = "SELECT * FROM articles WHERE id = :id";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$article = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$article) {
|
|
die("Article introuvable.");
|
|
}
|
|
}
|
|
|
|
if (isset($_POST['confirm']) && $_POST['confirm'] === 'Oui') {
|
|
$sql = "DELETE FROM articles WHERE id = :id";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
|
|
|
if ($stmt->execute()) {
|
|
$message = "Article supprimé avec succès !";
|
|
$article = null;
|
|
} else {
|
|
$message = "Erreur lors de la suppression.";
|
|
}
|
|
}
|
|
|
|
require '../includes/header.php';
|
|
?>
|
|
|
|
<main>
|
|
<h2>Supprimer un article</h2>
|
|
|
|
<?php if($message) echo '<p>'.$message.'</p>'; ?>
|
|
|
|
<?php if($article): ?>
|
|
<p>Voulez-vous vraiment supprimer l'article : "<strong><?= htmlspecialchars($article['titre']) ?></strong>" ?</p>
|
|
<form method="POST">
|
|
<button type="submit" name="confirm" value="Oui">Oui</button>
|
|
<button type="submit" name="confirm" value="Non">Non</button>
|
|
</form>
|
|
<?php else: ?>
|
|
<p>Aucun article sélectionné ou article déjà supprimé.</p>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
<?php
|
|
require '../includes/footer.php';
|
|
?>
|