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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| <?php include "css-pages-communes.php"; ?>
#cadre { border: 3px;
border-style: solid;
border-color: #848484;
border-radius: 10px;
padding-top: 0px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px;
background-color: #D8D8D8;
width: 660px;
height: auto;}
#interieur { background-color: #D8D8D8;
width: 660px;
height: auto;}
table { width: 690px; height: auto; border: 1px solid black; border-spacing: 0px; border-radius: 10px; text-align: center;}
th { border: 1px solid black; padding: 5px; background-color: red;}
table tbody tr td { border: 1px solid black; padding: 5px;}
.th1 { border-radius: 10px 0px 0px 0px;}
.th2 { border-radius: 0px 10px 0px 0px;}
.th3 { border-radius: 0px 0px 0px 10px;}
.th4 { border-radius: 0px 0px 10px 0px;}
.pair { background-color: red;}
.impair { background-color: black;}
<?php include "aspect-pages-communes.php"; ?>
<div id="haut">
<div id="marge">
<h3>Bienvenue dans notre espace avis</h3>
<p>Vous connaissez l'un de nos centres Kibéos?<br> Connectez-vous à votre compte Kibéos et laissez nous vos remarques, commentaires, avis, suggestions....<br><br>
<form action="avis.php" method="post" name="avis">
<label for="pseudo">Pseudo</label>
<input type="text" name="pseudo" size="106" maxlength="30"><br>
<label for="titre">Titre</label>
<input type="text" name="titre" size="106" maxlength="106"><br>
<label for="commentaire">commentaire</label>
<textarea name="commentaire" rows="4" cols="80" maxlength="300" wrap="hard" placeholder="Formulez votre avis"></textarea><br><br><br>
<input type="submit" value="Envoyer" name="submit">
<input type="reset" value="Recommencer">
</form>
<?php
// On vérifie que le formulaire vient d'être envoié.
if (!isset($_POST['submit']))
{
}
// On regarde si nos variables ne sont pas vides.
elseif ((isset($_POST['submit'])) && (!empty($_POST['pseudo'])) && (!empty($_POST['titre'])) && (!empty($_POST['commentaire'])))
{
// On teste la conformité d'écriture des champs.
// Pseudo
$_POST['pseudo'] = htmlspecialchars($_POST['pseudo']);
if (preg_match("#^[a-zA-Z0-9éèàêâùïüëô.-_]{3,30}$#", $_POST['pseudo']))
{
// Titre
$_POST['titre'] = htmlspecialchars($_POST['titre']);
if (preg_match("#^[a-zA-Z0-9éèàêâùïüëô;,.\"\'() _-]{3,106}$#", $_POST['titre']))
{
// Commentaire
$_POST['commentaire'] = htmlspecialchars($_POST['commentaire']);
if (preg_match("#^[a-zA-Z0-9éèàêâùïüëô;,.\"\'() _-]{3,300}$#", $_POST['commentaire']))
{
// Insertion des informations dans la base de données.
$bdd = new PDO('mysql:host=XXX;dbname=XXX', 'XXX', 'XXX');
$req = $bdd->prepare('INSERT INTO avis(pseudo, titre, commentaire) VALUES(:pseudo, :titre, :commentaire)');
$req->execute(array(
'pseudo' => $_POST['pseudo'],
'titre' => $_POST['titre'],
'commentaire' => $_POST['commentaire']));
}
else
{
echo 'Votre commentaire n\'est pas valide, il doit faire entre 3 et 300 caractères et ne doit pas contenir de caractères spéciaux, recommencez svp merci.';
}
}
else
{
echo 'Votre titre n\'est pas valide, il doit faire entre 3 et 106 caractères et ne doit pas contenir de caractères spéciaux, recommencez svp merci.';
}
}
else
{
echo 'Le Pseudo choisi n\'est pas valide, il doit faire entre 3 et 30 caractères et ne doit pas contenir de caractères spéciaux, recommencez svp merci.';
}
}
else
{
echo 'Veuillez remplir tous les champs et envoyer le formulaire svp, merci.';
}
// Poste du message sur la page avis.
$bdd = new PDO('mysql:host=XXX;dbname=XXX', 'XXX', 'XXX');
$reponse = $bdd->query('SELECT idavis, datavis, pseudo, titre, commentaire FROM avis ORDER BY idavis DESC LIMIT 0, 20');
?>
<table>
<thead> <!-- Entête de tableau -->
<tr>
<th class="th1">Id</th>
<th>Date</th>
<th>Pseudo</th>
<th>Titres</th>
<th class="th2">Commentaires</th>
</tr>
</thead>
<tfoot> <!-- Pied de tableau pour meilleure présentation -->
<tr>
<th class="th3"></th>
<th></th>
<th></th>
<th></th>
<th class="th4"></th>
</tr>
</tfoot>
<?php
//J'affiche les lignes de mon tableau une à une avec une boucle.
while ($donnees = $reponse->fetch())
{
if ($id%2 == 0)
{
echo "<tbody>
<tr class=\"pair\">
<td><?php echo htmlspecialchars($donnees[\'idavis\']);?></td>
<td><?php echo htmlspecialchars($donnees[\'datavis\']);?></td>
<td><?php echo htmlspecialchars($donnees[\'pseudo\']);?></td>
<td><?php echo htmlspecialchars($donnees[\'titre\']);?></td>
<td><?php echo htmlspecialchars($donnees[\'commentaire\']);?></td>
</tr>
</tbody>";
}
else
{
echo "<tbody>
<tr class=\"impair\">
<td><?php echo '.htmlspecialchars($donnees[\'idavis\']).';?></td>
<td><?php echo '.htmlspecialchars($donnees[\'datavis\']).';?></td>
<td><?php echo '.htmlspecialchars($donnees[\'pseudo\']).';?></td>
<td><?php echo '.htmlspecialchars($donnees[\'titre\']).';?></td>
<td><?php echo '.htmlspecialchars($donnees[\'commentaire\']).';?></td>
</tr>
</tbody>";
}
//Fermeture de la boucle.
}
$reponse->closeCursor();
?>
</table>
</div>
</div>
<?php include "pied-de-page.php"; ?> |
Partager