<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE>
	Sign My Guestbook
  </TITLE>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 </HEAD>
 <BODY OnLoad="document.MyForm.Name.focus();">
 <H1 ALIGN="center">Signing Iyad Abu-Jeib's Guestbook</H1>
<?

 $name = trim($_POST['Name']);
 $address = trim($_POST['Address']);
 $email = trim($_POST['Email']);
 $homepage = trim($_POST['Homepage']);
 $message = trim($_POST['Message']);
 $date = date('j F Y, H:i:s T');
 $ip = $_SERVER['REMOTE_ADDR'];

echo <<< BEGIN
<CENTER>
	<TABLE WIDTH="60%">
		<TR>
			<TD>
				<FORM name="MyForm" ACTION="{$_SERVER['PHP_SELF']}" METHOD="POST">
					<B>*NAME:</B> <INPUT NAME="Name" SIZE="30" TYPE="text" STYLE="width:100%;" value="$name">
					<B>Address:</B> <INPUT NAME="Address" SIZE="30" TYPE="text" STYLE="width:100%;" value="$address">
					<B>E-mail:</B> <INPUT NAME="Email" SIZE="30" TYPE="text" STYLE="width:100%;overflow-y:auto;" value="$email">
					<B>Homepage:</B> <INPUT NAME="Homepage" SIZE="30" TYPE="text" STYLE="width:100%;" value="$homepage">
					<B>*Message:</B> <TEXTAREA NAME="Message" ROWS="5" COLS="30" TYPE="text" STYLE="width:100%;">$message</TEXTAREA>
					<INPUT NAME="Submitted" TYPE="hidden" VALUE="TRUE">
					<CENTER>
						<INPUT TYPE="Submit" VALUE="SUBMIT"> 
						<INPUT TYPE="reset" VALUE="CLEAR">
					</CENTER>
				</FORM>
				<center><I>The fields marked with * must be filled out.</I></center>
			</td>
		</tr>
	</table>
BEGIN;

if (isset($_POST['Submitted'])) // Line 31
{
 $errors = array();
 if (empty($name))
	$errors[] = "You have to enter your name.";
 if (empty($message))
	$errors[] = "You have to write a message.";

 if (empty($email))
	$email = "NULL";
 if (empty($address))
	$address = "NULL"; // Line 50
 if (empty($homepage)) 
 	$homepage = "NULL";
 else 
 {
	$pos = stripos($homepage,"http://");
	if ($pos === false)
		$homepage = "http://".$homepage;
 }	
 
 if (!empty($errors))
 {
	echo "<h2 align=\"center\">Missing Information</h2><center>\n";
	echo "<FONT COLOR='red'>";
	foreach ($errors as $error)
		echo "$error<br>\n";
	echo "</FONT></center>\n";
 }
 else
 {
	@$d = mysql_connect('localhost','abu-jeib','iyad911') or  die("<p>Sorry, we can't process your request at this time.</p>");
	@mysql_select_db('guestbook') OR die("<p>Sorry, we can't process your request at this time.</p>");
	$q = "insert into gbook(name,date,homepage,email,address,message,ip) values 
		('$name','$date','$homepage','$email','$address','$message','$ip')";
	@$r = mysql_query($q) OR die("<p>Sorry, we can't process your request at this time.</p>");
	echo "<font color='red'>Thanks for signing my guestbook</font>";
	@mysql_close($d) OR die(); 
 } // else no errors
} // if submitted
?>
  <p><A href="view_guestbook.php">View My Guestbook</A></p>
 </center>
 </body>
</html>
