Hi everybody !!!
I'm following a tutorial on how to write a guestbook, and I have two questions...
First : I don't like the US time format, like : year, month, day. In french, it's day, month, year, and I'm afraid the users will get confused with a US format...
I thought about using the timestamp sthing, but as I don't master php well, I didn't get any result...
Second : I'd like to have the messages on different pages, let's say, 20 messages per page, not more... how can I do that ? I thing, counting the message number, and then, making a function which would print only 20 per page ?
Third ( and last ) : I'd like the "merci de votre message" ( basically thanking the user for writing a message ) to be written below the form, and still being able to see the rest of the messages...
I know I'm asking for a lot of things, sorry... I think it's quite basic, but I'm a newbie, so...
Here, I put the code :
sign.php
<?php
// ================================================== ====
// PHP GUESTBOOK TUTORIAL PART I
// Tutorial files taken from [url]http://www.daydreamgraphics.com/[/url]
// Only for illustration purposes, use as your own risk.
// Not for resale, profit-making, or distributed in anyway. Personal usage only.
// Copyrighted by Magdeline Ng, of [url]http://www.daydreamgraphics.com/[/url]
// ================================================== ====
// view.php
// SQL database Variables
$hostname="sql.free.fr"; //of course, I changed those to mine...
$user="myusername";
$pass="mypassword";
$dbase="mydatabasename";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Livre de Platine</title>
</head>
<body>
<form action="form.php" method="post">
<table width=100% border=0>
<tr>
<td>Nom : </td>
<td><input type="text" name="name" size=15></td>
</tr>
<tr>
<td>Email : </td>
<td><input type="text" name="email" size=15></td>
</tr>
<tr>
<td>Nom du Site : </td>
<td><input type="text" name="sitename" size=15></td>
</tr>
<tr>
<td>URL du Site :</td>
<td><input type="text" name="siteurl" size=15></td>
</tr>
<tr>
<td>Commentaires :</td>
<td><textarea name="comments" cols=30 rows=5></textarea></td>
</tr>
<tr>
<td colspan=2><input type="submit" name="Et hop !" value="Sign">
<input type="reset" name="Tout effacer !" value="Reset">
</td>
</tr></table>
</form>
<?php
// View Guestbook
$q="SELECT * from guestbookn order by date desc";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$name=$row["name"];
$email=$row["email"];
$sitename=$row["sitename"];
$siteurl=$row["siteurl"];
$date=$row["date"];
$comments=$row["comments"];
echo "<p><b>Nom :</b> $name<br>";
echo "<b>Email :</b> $email<br>";
echo "<b>Site :</b> <a href=\"$siteurl\">$sitename</a><br>";
echo "<b>Date :</b> $date<br>";
echo "<b>Commentaires :</b><br> $comments<br></p>";
}
?>
</body>
</html>
sign.php
<?php
// ================================================== ====
// PHP GUESTBOOK TUTORIAL PART I
// Tutorial files taken from [url]http://www.daydreamgraphics.com/[/url]
// Only for illustration purposes, use as your own risk.
// Not for resale, profit-making, or distributed in anyway. Personal usage only.
// Copyrighted by Magdeline Ng, of [url]http://www.daydreamgraphics.com/[/url]
// ================================================== ====
// SQL database Variables
$hostname="sql.free.fr";
$user="username";
$pass="psswd";
$dbase="dbname";
$connection = mysql_connect("$hostname" , "$user" , "$pass");
$db = mysql_select_db($dbase , $connection);
// for register globals off
$name = mysql_escape_string($_POST['name']);
$email = mysql_escape_string($_POST['email']);
$sitename = mysql_escape_string($_POST['sitename']);
$siteurl = mysql_escape_string($_POST['siteurl']);
$comments = mysql_escape_string(strip_tags($_POST['comments']));
$ip = $_SERVER['REMOTE_ADDR'];
if (empty($name) || empty($comments))
{
die ('On dirait que vous étiez trop pressé...');
}
// This is form.php
$q="INSERT into guestbookn (id,name,email,sitename,siteurl,date,ip,comments)
VALUES ('','$name','$email','$sitename','$siteurl',now(), '$ip','$comments')";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
if ($result)
{
echo "<p>Merci, $name. L'entrée a été enregistrée !</p>";
}
?>
<html>
<head>
<title>Entrée Enregistrée ! </title>
</head>
<body>
<p><a href="sign.php" target="_self">Retour au livre de platine</a></p>
</body></html>
This tutorial is cool, but I'd like to improve the guestbook a bit...
Thanks for your help !!! ( in the meantime, I'll keep on searching, maybe I come up with a solution for some of my problems... )
Thanks !!
Ness