I didn\\'t write this guestbook script. I just came across it and I\\'m pulling it apart so I can learn PHP. Problem is that it doesn\\'t execute but just goes to an url like http://mydomain.com/ /test.php (with 2 \\"/ /\\" and a space in
between) Can anybody help me figure out what\\'s wrong or suggest how I can locate the problem?
Thanks
<head>
<title>Test</title>
</head>
<style>
<!--
A:link {text-decoration: none ; color:0000ff}
A:visited {text-decoration: none; color:004080}
A:active {text-decoration: none}
A:hover {text-decoration: underline; color:ff0000}
-->
</style>
<body bgcolor=#FFFFCC>
<?
require(\\\"test.inc\\\");
//******************************************************************
//******************************************************************
//initialize database info
//******************************************************************
$server= \\\"localhost\\\"; //mysql server address
$dbname= \\\"book\\\"; // mysql database name
$uid= \\\"name\\\"; // username for that database
$pwd= \\\"password\\\"; // 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
?>
<form action=\\\"<?php echo $PHP_SELF?>\\\" method=\\\"POST\\\">
Login Name: <input type=\\\"Text\\\" name=\\\"loginname\\\"><br>
Password: <input type=\\\"Password\\\" name=\\\"pword\\\"><br>
<input type=\\\"Submit\\\" value=\\\"Login\\\">
</form>
<?php
//******************************************************************
}else{ //do guestbook
?>
<?php
//******************************************************************
//make connection to the database
//******************************************************************
$conn=mysql_connect($server,$uid,$pwd);
mysql_select_db($dbname, $conn);
//******************************************************************
//I know, it can be faked
//we\\\'ll skip db updates if not matched, but let them see the entries
//******************************************************************
if(eregi($PHP_SELF,$HTTP_REFERER)){
//******************************************************************
//if autodelete, delete old entries
//******************************************************************
if($autodelete){
$sql= \\\"delete from $bookname where posted<\\\".
(time()-($autodelete * 86400));
mysql_query($sql,$conn);
}
//******************************************************************
//Are deleting an entry?
//******************************************************************
if($d>0){
$sql= \\\"delete from $bookname where id=$d\\\";
mysql_query($sql,$conn);
}
//******************************************************************
//check to see if admin logged in
//******************************************************************
$isadmin=0;
if($loginname==$user && $pword==$password)$isadmin=1;
//******************************************************************
//Are posting a new entry?
//******************************************************************
if($action== \\\"Submit\\\"){
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>\\\");
}else{
if($name && $email && $company && $message){
$sql= \\\"insert into $bookname (posted,name,email,company,message) \\\".
\\\"values (\\\".time(). \\\",\\\'\\\".addslashes($name). \\\"\\\', \\\".
\\\"\\\'\\\".addslashes($email). \\\"\\\', \\\'\\\".addslashes($company). \\\"\\\', \\\".
\\\"\\\'\\\".addslashes($message). \\\"\\\')\\\";
$result=mysql_query($sql,$conn);
if(!$result){
echo( \\\"There was an error! \\\".mysql_errno(). \\\": \\\".mysql_error());
}else{
echo(
\\\'<center><p><b>Thank you for adding a n entry</b></p></center>\\\');
//notify via email
if($notify){
$emailmessage= \\\"A new entry has been posted:\\\\n\\\\n\\\".
\\\"By: $name\\\\nemail: $email\\\\nCompany: $company\\\\n\\\".
\\\"Message:\\\\n$message\\\\n\\\\n\\\";
mail($email, \\\"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 HTTP_REFERER check
//******************************************************************
//show guestbook entries
//******************************************************************
$sql=
\\\"select id,name,email,company,posted,message from $bookname order by posted desc\\\";
if(($result=mysql_query($sql,$conn))){
while(($rs=mysql_fetch_array($result))){
echo( \\\'<hr><p>\\\');
if($isadmin){?>
<form action=\\\"<?php echo $PHP_SELF ?>\\\" method=\\\"POST\\\">
<input type=\\\"hidden\\\" name=\\\"loginname\\\" value=\\\" <?php echo($loginname);?>\\\">
<input type=\\\"hidden\\\" name=\\\"password\\\" value=\\\" <?php echo($password);?>\\\">
<input type=\\\"hidden\\\" name=\\\"d\\\" value=\\\" <?php echo($rs[0]);?>\\\">
<input type=\\\"Submit\\\" value=\\\"Delete\\\"><br>
<?php }
echo( \\\"Name: <b>$rs[1]</b><br>\\\\n\\\");
echo( \\\"Email: <a href=\\\\\\\"mailto:$rs[2]\\\\\\\">$rs[2]</a><br>\\\\n\\\");
echo( \\\"Company: $rs[3]<br>\\\\n\\\");
echo( \\\"Date: \\\".date( \\\"m-d-Y\\\",$rs[4]). \\\"<br>\\\\n\\\");
echo( \\\"Message:<br>$rs[5]</p>\\\");
if($isadmin)echo( \\\'</form>\\\');
}
mysql_freeresult($result);
}else{
echo( \\\"There was an error! \\\".mysql_errno(). \\\": \\\".mysql_error());
}
//******************************************************************
//shutdown database connection
//******************************************************************
mysql_close($conn);
?>
<form action=\\\" <?php echo $PHP_SELF?>\\\" method=\\\"POST\\\">
Name: <input type=\\\"Text\\\" name=\\\"name\\\" size=\\\"40\\\" maxlength=\\\"50\\\"><br>
Email: <input type=\\\"Text\\\" name=\\\"email\\\" size=\\\"35\\\" maxlength=\\\"40\\\"><br>
Company: <input type=\\\"Text\\\" name=\\\"company\\\" size=\\\"35\\\" maxlength=\\\"40\\\"><br>
Message:<br>
<textarea name=\\\"message\\\" cols=\\\"40\\\" rows=\\\"8\\\" wrap=\\\"PHYSICAL\\\">
<input type=\"Submit\" name=\"action\" value=\"Submit\">
<input type=\"reset\">
</form>
<hr>
<?php
//***************************************************************
} //end guestbook
//***************************************************************
?>