I was a little bored so I coded a PHP guest book for my site. I felt like sharing it with WJ as well!
index.php
post.php
The Database needs a table called guestbook and 4 fields
id, name, email, comment.
id, int, auto_increment
name varchar(40)
email varchar(100)
comment varchar(200)
You should be all set and have a guestbook for your website.
Let me know what you think, or add on to it!
index.php
Code:
<!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>Guest Book</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" link="#FFFFFF">
Please leave your comments.
<form action="../post.php" method="post">
Name: <br />
<input type="text" name="name" />
<br />
Email: <br />
<input type="text" name="email" />
<br />
Comment:
<br />
<textarea name="comment"></textarea>
<br />
<input type="submit" value="Submit Your Comment" />
</form>
<br />
<br />
Comments....
<br />
.........................................
<br /><br />
<?php
mysql_connect("localhost","username","password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$result = mysql_query("SELECT * FROM guestbook");
while($row = mysql_fetch_assoc($result)){
echo 'Comment Date: '. date('m-d-Y') ."<br/>";
echo "Name: ".$row['name']."<br/> Email: ".$row['email']."<br/> Comment: ".$row['comment']."<br/>......................................... <br/>";
}
?>
</body>
</html>
post.php
Code:
<!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>Posted</title>
</head>
<body>
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
mysql_connect("localhost","username","password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$add = mysql_query("INSERT INTO guestbook (name, email, comment) VALUES ('$name','$email','$comment')");
echo "Your name: $name.";
echo "<br/>";
echo "Your email: $email.";
echo "<br/>";
echo "Your Comment: $comment";
?>
<br /><br />
To view the guestbook click <a href="/index.php">here</a>
</body>
</html>
The Database needs a table called guestbook and 4 fields
id, name, email, comment.
id, int, auto_increment
name varchar(40)
email varchar(100)
comment varchar(200)
You should be all set and have a guestbook for your website.
Let me know what you think, or add on to it!