-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminichat.php
More file actions
88 lines (61 loc) · 1.47 KB
/
minichat.php
File metadata and controls
88 lines (61 loc) · 1.47 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>minichat</title>
</head>
<style>
form, h1 {text-align: center}
</style>
<body>
<h1>MINICHAT</h1>
<br />
<?php
// Connexion à la base de données
try
{
$bdd = new PDO('mysql:host=localhost;dbname=sdz;charset=utf8', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
// Récupération du pseudo le plus récemment enregistré
$reponse = $bdd->query('SELECT pseudo FROM minichat ORDER BY info_date DESC LIMIT 1');
$donnees = $reponse->fetch();
$reponse->closeCursor();
?>
<!-- Afficher le formulaire -->
<form action="minichat_post.php" method="post" >
<p>
<em>Pseudo : </em>
<!-- Affichage du dernier pseudo enregistré -->
<input type="text" name="pseudo" value="<?php echo $donnees['pseudo']; ?>" />
<br />
</p>
<p>
<em>Message :</em>
<input type="text" name="message" />
<br />
</p>
<p>
<input type="submit" value="Valider" />
</p>
</form>
<?php
// Afficher les 10 derniers messages avec date en format européen et pseudo
$reponse = $bdd->query('SELECT pseudo, message, DATE_FORMAT(info_date, \'%d/%m/%Y %Hh%im%ss\') AS infodate FROM minichat ORDER BY id DESC LIMIT 0, 10');
while ($donnees = $reponse->fetch())
{
?>
<p>
[<?php echo $donnees['infodate'];?>]
<strong><?php echo $donnees['pseudo'];?></strong> :
<?php echo $donnees['message'];?>
</p>
<?php
}
$reponse->closeCursor();
?>
<br />
</body>