|
|
|
Guestbook Tutorial
First: create in your database a table named 'guestbook' with
the properties like the code below.
CODE |
// CREATE TABLE guestbook (
// id int(11) NOT NULL auto_increment,
// name varchar(30) NOT NULL default '',
// email varchar(75) NOT NULL default '',
// url varchar(30) NOT NULL default '',
// info text NOT NULL,
// time varchar(40) NOT NULL default '',
// PRIMARY KEY (id),
// KEY id (id)
//) TYPE=MyISAM;
|
The Following html code will make your guestbook submition
form.
CODE |
<table cellpadding="0" cellspacing="0"><tr><td>
<form name="form1"
method="post" action="">
Name:
<input type="text"
name="name">
Email:
<input type="text"
name="email">
Http:
<input type="text" name="url">
Comment:
<textarea name="info"></textarea>
<input type="submit"
name="Submit3" value="submit">
</form><br><br>
|
The Following php code will make your guestbook work. Donīt
forget to keep it between the <? and ?>code.
use this first line to include the connection file to your
database.
CODE |
<?
include("connection_file.php");
Insert the new data into the database.
$time = time();
$name = nl2br(htmlentities(trim($name)));
$info = nl2br(htmlentities(trim($info)));
$url = ereg_replace('http://',"",$url);
if($name && $info){
mysql_query("insert into guestbook (name,email,url,info,time)
values ('$name', '$email', '$url', '$info',
'$time')");
echo "<br>Thanks for your comment!";
}
?>
|
Now lets select all the information in your database and show
them.
CODE |
<?
$result = mysql_query("SELECT * FROM guestbook
ORDER BY id DESC LIMIT 0,15");
if (mysql_num_rows($result)>0) {
while($row = mysql_fetch_array($result)){
$time = date("d-m-y H:i",$row[time]);
echo "<b>$row[name]: </b>";
if($row[email] != "") {
echo "| <a href='mailto:$row[email]'>email</a>
";
}
if($row[url] != "") {
echo "| <a href='http://$row[url]'
target='_blank'>www</a> ";
}
echo "$time<br>";
echo "$row[info]<br><br>";
}
}
echo "</td></tr></table>";
mysql_close();
?>
|
Tutorial By Xtasy
|
|