First of all you need to create a index.php file and a database of 4 columns which are -
1.id (BIGINT)(index = primary) AUTO INCREMENT = true
2.name (VARCHAR 250 characters)
3.message (VARCHAR 250 characters)
4.email (VARCHAR 250 characters)
Then in index.php file write the following codes to show the guestbook-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Guestbook - home</title>
</head>
<body>
<?php
// echo all the database data
require ("connect.php");
$q = mysql_query("SELECT * FROM guestbook ORDER by id desc");
$num = mysql_num_rows ($q);
if ($q > 0){
while ($data = mysql_fetch_assoc ($q)){
$name = $data['name'];
$message = $data['message'];
$email = $data['email'];
echo "<div style='background-color:yellow'>$name says <br> $message. <a href='mailto:$email'>Mail $name</a>. <a href='report.php'>Report spam and delete</a></div><hr />";
}
}
?>
</body>
</html>
Now create connect.php file with following code-
<?php
mysql_connect ('localhost','root','naveen');
mysql_select_db ('tutorials');
?>
Now insert anything in database and you can see it working.
1.id (BIGINT)(index = primary) AUTO INCREMENT = true
2.name (VARCHAR 250 characters)
3.message (VARCHAR 250 characters)
4.email (VARCHAR 250 characters)
Then in index.php file write the following codes to show the guestbook-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Guestbook - home</title>
</head>
<body>
<?php
// echo all the database data
require ("connect.php");
$q = mysql_query("SELECT * FROM guestbook ORDER by id desc");
$num = mysql_num_rows ($q);
if ($q > 0){
while ($data = mysql_fetch_assoc ($q)){
$name = $data['name'];
$message = $data['message'];
$email = $data['email'];
echo "<div style='background-color:yellow'>$name says <br> $message. <a href='mailto:$email'>Mail $name</a>. <a href='report.php'>Report spam and delete</a></div><hr />";
}
}
?>
</body>
</html>
Now create connect.php file with following code-
<?php
mysql_connect ('localhost','root','naveen');
mysql_select_db ('tutorials');
?>
Now insert anything in database and you can see it working.
0 comments:
Post a Comment