(
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"!
Field name-Datatype-Field size
id-Autonumber-Primary key
posted-number-long integer
name-text-100
email-text-40
company-text-100
location-text-100
message-memo
*/
//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
?>
Sign the Guest Book
\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. */
$name=$email=$company=$message=$loginname=$pword="";
while(list($header,$value)=each($HTTP_POST_VARS)){
eval("$".$header."=\"$value\";");
}
if($maxmessagelength && strlen($message)>$maxmessagelength){
echo("Your message is too long, please click on your back ".
"button and shorten the message. Thank You!
\n");
}elseif(strpos($email,"@")==false || strpos($email,".")==false){
echo "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\").
\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...
\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
\n";
$result = odbc_exec($conn,$sql);
if(!$result){
echo("There was an error!");
}else{
echo('Thank you for signing our guestbook!');
//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{
?>
You didn't fill in all the form variables, please click
on your browsers back button now, and complete the form.
Thank You!
');
if($isadmin){ //
echo "IS ADMINISTRATOR
\n";
?>
');
$bzm++;
}
odbc_free_result($result);
}else{
echo("There was an error!");
}
//shutdown database connection
odbc_close_all();
if ($action != "Submit") {
?>
Please sign our Guest Book