38 lines
911 B
PHP
38 lines
911 B
PHP
<?php
|
|
// Page qui affiche un article selon son ID
|
|
|
|
require 'include/db.php'; // Connexion à la base
|
|
|
|
// Récupération de l'ID depuis l'URL, par défaut 0 si absent
|
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
|
|
// Préparation et exécution de la requête SQL
|
|
$stmt = $pdo->prepare('SELECT * FROM articles WHERE id = ?');
|
|
$stmt->execute([$id]);
|
|
$article = $stmt->fetch();
|
|
|
|
// Si l'article n'existe pas, afficher un message 404
|
|
if (!$article) {
|
|
echo "<h1>404 - Article introuvable</h1>";
|
|
exit();
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title><?= htmlspecialchars($article['titre']) ?></title>
|
|
</head>
|
|
<body>
|
|
|
|
<h1><?= htmlspecialchars($article['titre']) ?></h1>
|
|
|
|
<!-- nl2br pour garder les retours à la ligne dans le contenu -->
|
|
<p><?= nl2br(htmlspecialchars($article['contenu'])) ?></p>
|
|
|
|
<p><a href="index.php">← Retour à l'accueil</a></p>
|
|
|
|
</body>
|
|
</html>
|