Hey guys, here's the Guestbook i made.
Ok so lets start.
First make a new database named "guestbook", And execute this SQL Script:
Code:
CREATE TABLE messages(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
nick VARCHAR(20) NOT NULL,
message TEXT NOT NULL,
ip TEXT NOT NULL,
time TEXT NOT NULL
);
Now make three new PHP files.
1.index.php:
[html]
<!-- This Guestbook has been made By Zebra -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Guestbook</title>
<style type="text/css">
body{
font-size:11pt;
font-family:Verdana;
}
</style>
<?php include "functions.php"; ?>
</head>
<body>
<table width="450" style="border:1px solid black;border-collapse:collapse;" align="center">
<th>Guestbook<hr /></th>
<?php ShowMsgs(); ?>
<tr>
<form action="" method="POST" style="text-align:center;">
<td>
<?php @Post($_POST['nick'],$_POST['msg'],$_POST['submit']); ?>
Nickname:<input type="text" name="nick" size="33" /><Br />
Message:<br />
<textarea name="msg" cols="35" rows="8" tabindex="100" ></textarea>
<br />
<input type="submit" name="submit" value="Post" />
</td>
</form>
</tr>
</table>
</body>
</html>
[/html]
2.config.php(Remember to edit the host,user,password):
[php]
<?php
$host = "localhost"; //Put here your mysql host
$user = "root"; //Put here you mysql user
$pass = "root"; //Put here you mysql pass
$db = "guestbook"; //Put here the DB your using
$conn = mysql_connect($host,$user,$pass) or die(mysql_error());
$sdb = mysql_select_db($db) or die(mysql_error());
?>
[/php]
3.functions.php:
[php]
<?php
include "config.php";
function ShowMsgs(){
$sq = mysql_query("SELECT * FROM `messages` ORDER BY `id` DESC");
while($row = mysql_fetch_array($sq)){
echo "
<tr>
<td>
" . $row['time'] . " - " . $row['nick'] . ":<br />" . nl2br(htmlentities($row['message'])) . "<br /><hr />
</td>
</tr>
";
}
}
function Post($nick,$msg,$sub){
if(isset($sub)){
$nick = mysql_real_escape_string($nick);
$msg = mysql_real_escape_string($msg);
$ip = $_SERVER['REMOTE_ADDR'];
$h = date("g") - 1;
$time = date($h . ":i A:j/n/Y");
if($nick == ""){
echo "<font color='red'>You must provide a Nickname.</font><br />";
}elseif(strlen($nick) > 20){
echo "<font color='red'>Your nick must be between 1 And 20 Charecters.</font><br />";
}elseif(strlen($msg) < 6){
echo "<font color='red'>Your Message is to short.</font><br />";
}elseif($msg == ""){
echo "<font color='red'>You must provide a Message.</font><br />";
}else{
$insert = mysql_query("INSERT INTO `messages` (`nick`,`message`,`ip`,`time`) VALUES ('" . $nick . "','" . $msg . "','" . $ip . "','" . $time . "') ");
if($insert == true){
Header("Location:index.php");
}else{
echo "<font color='red'>There was a problem posting your comment.</font><br />";
}
}
}
}
?>
[/php]
Ok, now you have your own Guestbook ^^.
Download files:https://mesolottery.com/other/Guestbook.zip
-Zebra