Refonte complète du projet
This commit is contained in:
45
public/delete.php
Normal file
45
public/delete.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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'; ?>
|
||||
Reference in New Issue
Block a user