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
| <?php
// On test d'abord si php se connecte à la BDD Mysql
try
{
$bdd = new PDO('mysql:host=localhost;dbname=minichat;charset=utf8', 'root','root');
}
catch(Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
?>
<!-- Mon formulaire tres simple-->
<form method="post">
<table>
<tr>
<td><p>Pseudo : </p></td>
<td><input type="text" name="prenom" placeholder="prenom"></input></td>
</tr>
<tr>
<td><p>Message : </p></td>
<td><input type="text" name="message" placeholder="Message"></input></td>
</tr>
<tr>
<td><button type="submit" name="ajouterListe">Ajouter à la liste</button></td>
<td><button type="submit" name="finirListe">Terminer la liste</button></td>
</tr>
</table>
</form>
<!-- Traitement du bouton ajouterListe-->
<?php
if(isset($_POST['ajouterListe']))
{
$prenom = $_POST['prenom'];
$message = $_POST['message'];
$insertBdd = $bdd->prepare("INSERT INTO personne (prenom,message) VALUES (?,?)");
$insertBdd->execute(array($prenom,$message));
echo "Prénom et message envoyé dans la BDD.";
}
?>
<!-- Traitement du bouton finirListe-->
<?php if(isset($_POST['finirListe']))
{
?>
<table>
<tr>
<th>Prenom</th>
<th>Message</th>
<th>id</th>
<th>idListe</th>
</tr>
<?php $recup = $bdd->query("SELECT * from personne");
while($donnees = $recup->fetch())
{
?>
<tr>
<td><?php echo $donnees['prenom'] ?></td>
<td><?php echo $donnees['message'] ?></td>
<td><?php echo $donnees['id'] ?></td>
<td><?php echo $donnees['idListe'] ?></td>
</tr>
<?php
}
}
?>
</table> |
Partager