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
|
<?php
session_start();
$bdd = new PDO('mysql:host=127.0.0.1;dbname=membres', 'root', '');
if(isset($_SESSION['pseudo'])AND isset($_POST['message']) AND !empty($_SESSION['pseudo']) AND !empty($_POST['message']))
{
$pseudo = htmlspecialchars($_SESSION['pseudo']);
$message = htmlspecialchars($_POST['message']);
$insertmsg = $bdd->prepare('INSERT INTO chat (pseudo, message) VALUES(?, ?)');
$insertmsg->execute(array($pseudo, $message));
}
?>
<html>
<head>
</head>
<body>
<form method="post" action="">
<textarea type="text" name="message" placeholder="Tapez votre message" ></textarea><br>
<input type="submit" value="Envoyer" />
</form>
<?php
$allmsg = $bdd->query('SELECT * FROM chat ORDER BY id DESC');
while($msg = $allmsg->fetch())
{
?>
<B><?php echo $msg['pseudo']; ?> : </B><?php echo $msg['message']; ?> <br>
<?php
}
?>
</body>
</html> |
Partager