first commit
This commit is contained in:
38
article.php
Normal file
38
article.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// Page qui affiche un article selon son id dans l'URL
|
||||
|
||||
include 'include/db.php';
|
||||
|
||||
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();
|
||||
|
||||
if (!$article) {
|
||||
echo "<h1>404 - Article introuvable</h1>";
|
||||
exit();
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title><?php echo htmlspecialchars($article['titre']); ?></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1><?php echo htmlspecialchars($article['titre']); ?></h1>
|
||||
|
||||
<p><?php echo nl2br(htmlspecialchars($article['contenu'])); ?></p>
|
||||
|
||||
<p><a href="index.php">← Retour à l'accueil</a></p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user