Ajouter public/article.php

This commit is contained in:
2025-10-30 11:45:25 +00:00
parent f223f6b1e6
commit a01d7875a9

31
public/article.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
require_once __DIR__ . '/../src/db.php';
require_once __DIR__ . '/../src/functions.php';
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if ($id <= 0) {
http_response_code(404);
include __DIR__ . '/404.php';
exit;
}
$stmt = $pdo->prepare('SELECT * FROM articles WHERE id = :id');
$stmt->execute(['id' => $id]);
$article = $stmt->fetch();
if (!$article) {
http_response_code(404);
include __DIR__ . '/404.php';
exit;
}
?>
<!doctype html>
<html>
<head><meta charset="utf-8"><title><?php echo esc($article['titre']); ?></title>
<link rel="stylesheet" href="/public/assets/style.css"></head>
<body>
<header><h1><?php echo esc($article['titre']); ?></h1></header>
<main>
<p><em>Publié le <?php echo esc($article['date_creation']); ?></em></p>
<div><?php echo nl2br(esc($article['contenu'])); ?></div>
</main>
<footer><a href="/public/index.php">Retour</a></footer>
</body>
</html>