quelque amelioration

This commit is contained in:
2025-11-02 23:20:42 +01:00
parent 26c06eae90
commit 296b5c5a62
19 changed files with 461 additions and 328 deletions

View File

@@ -1,19 +1,17 @@
<?php
// Page qui affiche un article selon son id dans l'URL
// Page qui affiche un article selon son ID
include 'include/db.php';
require 'include/db.php'; // Connexion à la base
if (isset($_GET['id'])) {
$id = (int)$_GET['id'];
} else {
$id = 0;
}
// Requête SQL pour récupérer toutes les infos de l'article avec l'id donné
$sql = "SELECT * FROM articles WHERE id = ?";
$req = $pdo->prepare($sql);
$req->execute([$id]);
$article = $req->fetch();
// 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();
@@ -24,13 +22,14 @@ if (!$article) {
<html lang="fr">
<head>
<meta charset="utf-8">
<title><?php echo htmlspecialchars($article['titre']); ?></title>
<title><?= htmlspecialchars($article['titre']) ?></title>
</head>
<body>
<h1><?php echo htmlspecialchars($article['titre']); ?></h1>
<h1><?= htmlspecialchars($article['titre']) ?></h1>
<p><?php echo nl2br(htmlspecialchars($article['contenu'])); ?></p>
<!-- 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>