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
|
<?php
$bdd = new PDO("mysql:host=localhost;dbname=chat;charset=utf8", "root", "");
if(isset($_POST['pseudo']) AND isset($_POST['message']) AND !empty($_POST['pseudo']) AND !empty($_POST['message']))
{
$pseudo = htmlspecialchars($_SESSION['pseudo']);
$message = htmlspecialchars($_POST['message']);
$insertmsg = $bdd->prepare('INSERT INTO tchat(pseudo, message) VALUES(?, ?)');
$insertmsg->execute(array($pseudo, $message));
}
?>
<html>
<head>
<title>Test de chat</title>
<meta charset="utf-8">
<meta http-equiv="Refresh" content="40">
</head>
<body>
<br>
<a href="iframe.php">Rafraichir la page !</a>
//de ici
<?php
$allmsg = $bdd->query('SELECT * FROM tchat ORDER BY id DESC');
while($msg = $allmsg->fetch())
{
?>
<font size="7pt"><center><b><?php echo $msg['pseudo']; ?> :</b> <?php echo $msg['message']; ?><br/></center></font>
<?php
}
?>
//à ici
</body>
</html> |
Partager