1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| <?php
session_start();
?>
<?php
$bdd = new PDO("mysql:host=127.0.0.1;dbname=inscription;charset=utf8", "root", "");
$bdd = new PDO("mysql:host=127.0.0.1;dbname=articles;charset=utf8", "root", "");
if(isset($_GET['id']) AND !empty($_GET['id'])) {
$get_id = ($_GET['id']);
$article = $bdd->prepare('SELECT * FROM articles WHERE id = ?');
$article->execute(array($get_id));
if($article->rowCount() == 1) {
$article = $article->fetch();
$id = $article['id'];
$titre = $article['titre'];
$contenu = $article['contenu'];
$likes = $bdd->prepare('SELECT id FROM likes WHERE id_article = ?');
$likes->execute(array($id));
$likes = $likes->rowCount();
$dislikes = $bdd->prepare('SELECT id FROM dislikes WHERE id_article = ?');
$dislikes->execute(array($id));
$dislikes = $dislikes->rowCount();
} else {
die('Cet article n\'existe pas !');
}
} else {
die('Erreur');
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?= $titre ?></title>
<meta charset="utf-8" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body class="homepage is-preload">
<?php
$bdd = new PDO('mysql:host=127.0.0.1;dbname=articles;charset=utf8','root','');
if(isset($_GET['id']) AND !empty($_GET['id'])) {
$getid = ($_GET['id']);
$article = $bdd->prepare('SELECT * FROM articles WHERE id = ?');
$article->execute(array($getid));
$article = $article->fetch();
if(isset($_POST['submit_commentaire'])) {
if(isset($_POST['pseudo'],$_POST['commentaire']) AND !empty($_POST['pseudo']) AND !empty($_POST['commentaire'])) {
$pseudo = ($_POST['pseudo']);
$commentaire = ($_POST['commentaire']);
if(strlen($pseudo) < 255) {
$ins = $bdd->prepare('INSERT INTO commentaires (pseudo, commentaire, id_article) VALUES (?,?,?)');
$ins->execute(array($pseudo,$commentaire,$getid));
$c_msg = "<span style='color:green'>Votre commentaire a bien été posté</span>";
} else {
$c_msg = "Erreur: Le pseudo doit faire moins de 255 caractères";
}
} else {
$c_msg = "<span style='color:red'>Erreur: Tous les champs doivent être complétés</span>";
}
}
$commentaires = $bdd->prepare('SELECT * FROM commentaires WHERE id_article = ? ORDER BY id DESC');
$commentaires->execute(array($getid));
?>
<div id="page-wrapper">
<!-- Header -->
<section id="header">
<div class="container">
<!-- Logo -->
<img class="background_nav" src="#" alt="">
<h1 id="logo">Un peu de lecture ?</h1>
</div>
</section>
<section id="main">
<div class="container">
<div id="content">
<!-- Post -->
<article class="box post">
<header>
<h2><?= $titre ?></h2>
<p><?= $contenu ?></p> <br/>
<a href="php/action.php?t=1&id=<?= $id ?>">J'aime</a> (<?= $likes ?>)
<br />
<a href="php/action.php?t=2&id=<?= $id ?>">Je n'aime pas</a> (<?= $dislikes ?>) <br/>
<a href="page_articles">Page précédente</a>
<br/><br/>
<section>
<div class="">
<form method="POST">
<input type="text" name="pseudo" value="<?= $_SESSION['name'] ?>" /><br />
<textarea name="commentaire" placeholder="Votre commentaire..."></textarea><br />
<input type="submit" value="Poster mon commentaire" name="submit_commentaire" />
</form>
</section>
</form> <br/>
<h2>Les commentaires</h2>
<?php
$grosMots = array('je vous épargne ces mots');
$remplacement = '*';
?>
<?php if(isset($c_msg)) { echo $c_msg; } ?>
<br /><br />
<?php while($c = $commentaires->fetch()) {
$c['commentaire'] = str_replace($grosMots, $remplacement, strtolower($c['commentaire']));
echo "<br/>";
echo "<br/>";
echo '<span style="background-color:white; color:black; font-size:200%; text-decoration:underline">'.$c['pseudo'].'</span>' ;
echo "<br/>";
echo '<span style="color:black;">'.nl2br($c['commentaire']).'</span>';}
?>
<?php } ?>
<?php
?>
</body>
</html> |
Partager