<?php require("guestbook-data.php3"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<!-- saved from url=(0040)http://px.sklar.com/code.html?code_id=50 -->
</COMMENT><HTML><HEAD>
<META content='"MSHTML 5.00.0910.1309"' name=GENERATOR>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type></HEAD>
<BODY>
<?php
/*
*****************************************************************
PHP-mySQL GuestBook
by Shane Caraveo (shane@caraveo.com)
DO NOT EMAIL ME ASKING HOW TO SET THIS UP!
I do not support this script in any way. If you fix a bug,
or add a cool feature, let me know.
Use of this script means you recognize the fact that I am not
responsible if this script blows up your machine (or causes
any other problems).
feel free to use and abuse this script in whatever
form or fashion you feel fit.
PHP-ODBC Guestbook modifications
by Brad Marsh (research4@snowcrest.net)
In somefile.php you need to have the following code:
$user="shane"; // admin username
$password="test"; // admin password
$bookname="mybook"; // the name of the table within the mysql db
$autodelete=0; //number of days before removal. 0 = disabled
$notify=0; //notify via email new postings 1=on 0=off
$email=""; //address to notify
require("guestbook-data.php3");
For the modified version, you need in guestbook-data.php3:
<?php
$user="name"; // admin username
$password="test"; // admin password
$bookname="book"; // the name of the table within the ODBC db
$autodelete=0; //number of days before removal. 0 = disabled
$notify=0; //notify via email new postings 1=on 0=off
$notify_email="yourname@yourISP.com"; //address to notify
?>
accessing your guestbook page with ?admin gets you the admin logon
which you use the above user and password to gain entry. The admin
page is identical to the regular guestbook page except that it lets
you delete entries.
mysql table info:
create table <tablename>(
id int not null auto_increment,
posted int not null,
name char(50) not null,
email char(40),
company char(40),
message text,
index (posted),
index (id)
)\g
ODBC database info (in my case it was Access - brad):
Don't forget to create a System DSN called "guestbook"!
//******************************************************************
//initialize database info
//******************************************************************
$server="127.0.0.1"; //database server address
$dbname="guestbook"; //ODBC DSN database name
$uid=""; // username for that database
$pwd=""; // password for that database
$maxmessagelength=1024; //set to 0 if you dont care how long it gets
//******************************************************************
//no need to edit below this line
//******************************************************************
//******************************************************************
//check to see if admin login requested
//******************************************************************
if($argv[0]=="admin"){ //show login form
?>
//******************************************************************
if (!$action) { // Don't show the link to sign the guestbook if they've already done it
?>
<a href="guestbook.php3#post">Sign the Guest Book</a><br>
<?php
}
//******************************************************************
// Connect to the database
$conn=odbc_connect($dbname,$uid,$pwd) or die( "Unable to connect to database" );
//******************************************************************
//if autodelete, delete old entries
//******************************************************************
if($autodelete){
$sql="delete from $bookname where posted<".
(time()-($autodelete * 86400));
$result = odbc_exec($conn,$sql);
}
/* Are deleting an entry? */
if($d!=""){
$sql="delete from $bookname where id=$d";
if ($result = odbc_exec($conn,$sql)) {
odbc_free_result($result);
} else {
echo "Oops. Failed to delete.<br>\n";
}
}
//******************************************************************
//check to see if admin logged in
//******************************************************************
$isadmin=0;
if($loginname==$user && $pword==$password)$isadmin=1;
//******************************************************************
//Are posting a new entry?
//******************************************************************
if($action=="Submit"){
/* Over-write some variables from the postvars to be sure
they were at least done via post method. */
if($maxmessagelength && strlen($message)>$maxmessagelength){
echo("<p>Your message is too long, please click on your back ".
"button and shorten the message. Thank You!</p>\n");
}elseif(strpos($email,"@")==false || strpos($email,".")==false){
echo "<p>You submitted an invalid email address. Please click your back ".
"button and enter a valid email address (of the form \"your_username@your_ISP.com\").</p>\n";
} else {
if($name && $email && $company && $message){
$test = odbc_exec($conn,"select id from $bookname where (name='$name' and email='$email')");
if (odbc_fetch_row($test)==true) {
echo "Identical record found; updating...<br>\n";
$old_id = odbc_result($test,"id");
$sql="update $bookname set posted=".time().
",name='$name',email='$email',company='$company',location='$location',message='$message' where id=$old_id";
}else{
$sql="insert into $bookname (posted,name,email,company,location,message) ".
"values (".time().",'".$name."', ".
"'".$email."', '".$company."', ".
"'".$location."', '".$message."')";
}
//echo "$sql<br>\n";
$result = odbc_exec($conn,$sql);
if(!$result){
echo("There was an error!");
}else{
echo('<center><b>Thank you for signing our guestbook!</b></center>');
//notify via email
if($notify){
$emailmessage="Your guestbook has been signed:\n\n".
"By: $name\nemail: $email\nCompany: $company\n".
"Location: $location\nMessage:\n$message\n\n";
//mail($notify_email,"Guestbook Notification",$emailmessage);
}
}
}else{
?>
<p>You didn't fill in all the form variables, please click
on your browsers back button now, and complete the form.
Thank You!</p>
<?php
}
}
} // End of "if action" statement
//show guestbook entries
//******************************************************************
$sql="select * from $bookname order by posted desc";
if(($result = odbc_exec($conn,$sql))){
$bzm = 1;
while(odbc_fetch_row($result,$bzm)) {
echo('<hr><p>');
if($isadmin){ //
echo "<b>IS ADMINISTRATOR</b><br>\n";
?>