This is just a really quick half-hour project I started due to bordem.
Anyway, it's all one page and the SQL file will be posted too.
guestbook.php
mysql.sqlPHP Code:<?php
echo '<html>
<head>
<title>My Guestbook</title>
</head>';
//mysql
$db = "guestbook"; //your DB name
$pass = "hello123"; //your DB password
$user = "root"; //your DB username
$host = "localhost"; //where is your DB hosted? [usually localhost]
$connect = @mysql_connect($host, $user, $pass) or die ('Sorry, I can not connect to your MySQL Database!');
mysql_select_db($db) or die ('Sorry, I can not open your MySQL Database!');
//mysql
//config
$admin_ip = "127g.0.0.1"; //PUT YOUR REAL IP HERE!
//config
//functions
function protect($str){
$new = strip_tags($str);
return $new;
}
function file_extension($filename){
return end(explode(".", $filename));
}
//functions
if($_POST[send_message]){
$name = protect($_POST['name']);
$web = protect($_POST['web']);
$avatar = protect($_POST['avatar']);
$email = protect($_POST['email']);
$comment = protect($_POST['comment']);
$ip = $_SERVER['REMOTE_ADDR'];
$date = date("F jS Y");
if(!$name || !$web || !$email || !$comment || !$ip || !$date){
echo 'All fields are required!<br /><a href="guestbook.php">Back</a>';
}else{
if(!$avatar){
$avatar = 'http://i28.tinypic.com/29zyayv.jpg';
}else{
$formats = array('jpeg', 'jpg', 'tiff', 'png', 'gif', 'bmp');
if(!in_array(file_extension($avatar), $formats)){
$avatar = 'http://i28.tinypic.com/29zyayv.jpg';
}else{
$avatar = $avatar;
}
}
$f = str_replace('http://', '', $web);
$f = str_replace('www.', '', $f);
$web = 'http://www.' . $f . '/';
if(strpos($email, ".") == false || strpos($email, "@") == false){
echo 'You must enter a valid E-Mail!<br /><a href="guestbook.php">Back</a>';
}else{
mysql_query("INSERT INTO `messages` (`name`, `web`, `email`, `avatar`, `comment`, `ip`, `date`) VALUES ('$name', '$web', '$email', '$avatar', '$comment', '$ip', '$date');");
echo 'Thank you for your comment, <b>'.$name.'</b>!<br /><a href="guestbook.php">Return to the Guestbook!</a>';
}
}
}else{
echo 'Welcome to my guestbook!<br /><hr />';
$msgs = mysql_query("SELECT * FROM messages ORDER BY `id` DESC");
if(mysql_num_rows($msgs) == 0){
echo 'Sorry, there are no messages!<br />Why not leave one below?';
}else{
while($r = mysql_fetch_array($msgs)){
$name = $r["name"];
$web = $r["web"];
$email = $r["email"];
$avatar = $r["avatar"];
if($_SERVER['REMOTE_ADDR'] == $admin_ip){
$ip = $r["ip"] . ' - ';
}else{
$ip = '';
}
$comment = $r["comment"];
$date = $r["date"];
echo '<table width="284" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="font-size: 7px; vertical-align: bottom;"><img src="http://i26.tinypic.com/30siwk8.png" width="8" border="0" height="8"></td>
<td style="font-size: 7px; vertical-align: bottom; background-color: rgb(221, 221, 221);"><img src="http://i26.tinypic.com/hrhohx.jpg" width="268" border="0" height="1"></td>
<td style="font-size: 7px; vertical-align: bottom;"><img src="http://i25.tinypic.com/3127mz7.png"></td>
</tr>
</tbody>
</table>
<table style="margin-top: -2px;" width="284" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td colspan="3" style="background-color: rgb(221, 221, 221);" align="center">
<div style="padding: 0pt 8px;">
<table width="100%" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td width="50" valign="top"><a href="'.$web.'" target="_blank"><img size="q" height="50" width="50" style="border: 1px solid rgb(153, 153, 153);" src="'.$avatar.'" alt="'.$name.'" title="'.$name.'"></a></td>
<td width="8"></td>
<td valign="top">'.$comment.'<br />'.$ip.''.$date.'</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
<table width="284" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="font-size: 8px;" valign="top"><img src="http://i32.tinypic.com/21wp4y.png" width="24" border="0"></td>
<td style="font-size: 8px;" valign="top"><img src="http://i30.tinypic.com/wjgks0.png" width="236" border="0" height="9"></td>
<td style="font-size: 8px;" align="right" valign="top"><img src="http://i26.tinypic.com/2qbc9yd.png" border="0" height="9"></td>
</tr>
</tbody>
</table><br />';
}
}
echo '<hr /><form method="post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name" size="25"></td>
</tr>
<tr>
<td>Website:</td>
<td><input type="text" name="web" size="25"></td>
</tr>
<tr>
<td>E-Mail:</td>
<td><input type="text" name="email" size="25"></td>
</tr>
<tr>
<td>Avatar:</td>
<td><input type="text" name="avatar" size="25"></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea cols="30" rows="5" name="comment"></textarea></td>
</tr>
</table>
<input type="submit" name="send_message" value="Send Message"></form>';
}
echo '</html>';
?>
Images:PHP Code:CREATE TABLE IF NOT EXISTS `messages` (
`id` int(90) NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`web` varchar(150) NOT NULL,
`email` varchar(150) NOT NULL,
`comment` varchar(200) NOT NULL,
`ip` varchar(90) NOT NULL,
`date` varchar(90) NOT NULL,
`avatar` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
http://i27.tinypic.com/axi4gx.png http://i29.tinypic.com/iyd7pg.png
The least you could do is add credits :)
- m0nsta.
