Bonjour,
J' ai un fichier guestbook.php et je voudrais séparer le code en 3 parties :
1 fichier : form.html
2 fichier : insert.php
3 fichier : affiche.php
Pouvez vous m'aider ?
Merci à vous.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php // Inclusion du fichier infos_sql.php include 'infos_sql.php'; // Test du champ caché posted. if($_POST['posted']) { // Si tous les champs sont remplis. if(!empty($_POST['pseudo']) AND !empty($_POST['email']) AND !empty($_POST['message'])) { // On nettoie les données (sauts de ligne en trop ). $pseudo = trim(ucfirst(addslashes($_POST['pseudo']))); $email = trim(addslashes($_POST['email'])); $message = trim(ucfirst(addslashes($_POST['message']))); // On définit la requête dinsertion. $insert = "INSERT INTO guestbook VALUES('','$pseudo','$email','$message','$date')"; // On exécute linsertion des données dans la table. $query = mysql_query($insert) OR die("Impossible dajouter le message<br>".mysql_error()); // On affiche un message de remerciement au visiteur. echo '<script language="JavaScript">'; echo 'alert("Merci pour votre message !");'; echo '</script>'; } // sinon on affiche un message derreur et on redirige. else { echo '<script language="Javascript">'; echo 'alert("Remplissez chaque champ svp !");'; echo 'javascript:history.back(1);'; echo '</script>'; } } ?> <html> <head> <title>Livre d'or</title> </head> <body> <form action="<?php echo $PHP_SELF; ?>" method="POST"> <input type="hidden" name="posted" value="1"> <div align="center"> <center> <table border="0" cellpadding="4" cellspacing="5" width="60%" height="107" style="border-style: solid; border-width: 0"> <tr> <td width="32%" height="22" style="border: 1px solid #008000">Votre Pseudo :</td> <td width="68%" height="22" style="border: 1 px solid #008000"><input type="text" name="pseudo" size="46"></td> </tr> <tr> <td width="32%" height="21" style="border: 1px solid #008000">Votre Email :</td> <td width="68%" height="22" style="border: 1px solid #008000"><input type="text" name="email" size="46"></td> </tr> <tr> <td width="32%" height="21" valign="top" style="border: 1 solid #008000">Votre Message</td> <td width="68%" height="21" style="border: 1px solid #008000"><textarea rows="9" name="message" cols="63"></textarea></td> </tr> <tr> <td width="32%" height="21" style="border: 1px solid #008000"></td> <td width="68%" height="21" style="border: 1px solid #008000"><input type="submit" value="Soumettre" name="submit"> <input type="reset" value="Recommencer" name="reset"></td> </tr> </table> </center> </div> </form> <?php // On vérifie à quel endroit dans la table on récupère les messages. if(!$start) {$start=0;} // On effectue une requête de recherche et de sélection des messages. $rec = mysql_query("SELECT * FROM guestbook ORDER BY id DESC LIMIT ".$start.",".$nb); // On extrait les données une à une à laide dune boucle While() ; while ($row = mysql_fetch_assoc($rec)) { ?> <div align="center"> <center> <table border="0" cellpadding="4" cellspacing="0" width="60%"> <tr> <td width="100%" style="border: 1 solid #000000"> De <?php echo stripslashes($row['pseudo']); ?> le <?php echo $row['date']; ?></td> </tr> <tr> <td width="100%" style="border: 1 solid #000000"><?php echo nl2br(stripslashes($row['message'])); ?></td> </tr> </table> </center> </div> <br><br> <?php } // On libère la mémoire cache après la requête. mysql_free_result($rec); // On compte le nombre denregistrements. $result=mysql_query("SELECT COUNT(*) FROM guestbook"); $row = mysql_fetch_row($result); ?> <p align="left"></p> <p align="center"> <?php // On utilise un script pour un affichage du nombre de pages : if ($start == "0") { echo"<b><font size=\"1\" face=\"Verdana\">[1]</font></b>"; } else { echo"<a href=\"guestbook.php?start=0\">[1]</a> "; } for($index=1;($index*$nb)<$row[0];$index++) { $pg = $index+1; if(($index*$nb)!=$start) { print("<a href=\"guestbook.php?start=".($index*$nb)."\">"); echo"[".$pg."]"; print("</a>"); } else { echo" <b><font size=\"1\" face=\"Verdana\">[".$pg."]</font></b>"; } } ?> </p> <p align="center"> </p> </body> </html>
Partager