I am having trouble creating a guestbook using php? I used functions but when I upload it to the server that I am using it is saying that my closing </html> tag is missing something. I have no idea what it is either. I was wondering if someone could help me out and take a look at my code.
<?php echo "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?".">"; ?>
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Guestbook</title>
<head>
<style type="text/css">
body {background-color: #FFCCCC}
h1 {color: #9966FF}
b, p {color: #9966FF}
</style>
</head>
<body>
<?php
// data grabbing here/
$fname = $_POST ['fname'];
$lname = $_POST ['lname'];
$gender = $_POST ['gender'];
$comment = $_POST ['comment'];
$submit = $_POST ['submit'];
function displayContents ($guestbookfile)
{
@$mf = fopen("../guestbook/guestbook.txt", "r");
if (!$mf)
{
$out = "<p class\"err\">Could not open the guestbook file for reading!</p>";
}
else
{
while (!feof($mf))
{
$entry = fgets($mf, 3000);
if (!feof($mf))
{
$data = explode("\t", $entry);
$out .= "<blockquote><span class=\"quote\">" . stripslashes($data [7]) ."</span><br />";
$out .= "<cite>-<span class=\"author\">$data[3] $data[4]</span><br /";
$out .= "A $data[5] $data[6]<br />";
$out .= "From $data [2]<br />";
$out .= "at $data[0] on $data[1]";
$out .= "</cite></blockquote>\n";
}
}
fclose($mf);
}
return $out;
}
function displayForm($fname, $lname, $gender, $comment, $err)
{
echo "err\n";
?>
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
<div>
<p><b>First Name:<br />
<input type="text" name="fname" id="fname" value="<?php echo $fname; ?>" /><br />
<br>
<p>Last Name:<br />
<input type="text" name="lname" id="lname" value="<?php echo $lname; ?>"/><br />
<br>
<p><b>Gender<br />
<label for="male">Male: </label><input type="radio" name="gender" id="male" value="male" <?php if ($gender == "male") echo "checked=\"checked\""; ?> /> <label for="female">Female: </label><input type="radio" name="gender" id="female" value="female" <?php if ($gender == "female") echo "checked=\"checked\""; ?> />
<p><b>Leave Some Feedback:<br />
<textarea name="comment" id="coment" rows="5" cols="25" <?php echo $comment; ?> /></textarea><br />
<br>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}
function insertData($outstring, $guestbook)
{
@$mf = fopen($gbFile, "a");
if (!$mf)
{
$err = "<p class=\"err\">Could not open guestbook file for writing!</p>";
}
else
{
if (flock($mf, LOCK_EX))
{
fwrite($mf, $outstring);
flock($mf, LOCK_UN);
fclose($mf);
$err = "success!";
}
else
{
$err = "<p class=\"err\">Could not establish a file lock!</p>";
}
}
return $err;
}
function processData($fname, $lname, $gender, $comment)
{
$outstring = date('h:i a') . "\t" . date('j F, Y') . "\t";
$outstring .= $_SERVER['REMOTE_ADDR'] . "\t";
$outstring .= addslashes(trim($fname)) . "\t" . addslashes(trim($lname)) . "\t";
$outstring .= $gender . "\t";
$outstring .= addslashes(trim($comment)) . "\n";
$err = insertData($outstring, "../guestbook/guestbook.txt");
if ($err = "success!")
{
echo displayContents("../guestbook/guestbook.txt");
}
else
{
echo $err;
}
function valid($fname, $lname, $gender, $comment)
{
if (is_null($fname) || empty($fname) || $fname == "") $err .= "Please enter your first name<br />";
if (is_null($lname) || empty($lname) || $lname == "") $err .= "Please enter your last name<br />";
if ($gender != "male" && $gender != "female") $err .= "Please indicate your sex<br />";
if (is_null($comment) || empty($comment) || $comment == "") $err .= "Please leave me some comments<br />";
return $err;
}
?>
</head>
<body><div id="main">
<?php
if ($submit == 'Submit') {
$err = valid($fname, $lname, $gender, $comment);
if ($err == "")
{
processData($fname, $lname, $gender, $comment);
exit;
}
}
if ($err == "")
{
$err = "<p>Plase fill out the following form:</p>";
}
else
{
$err = "<p class=\"err\">Please make the following corrections:<br />\n$err\n</p>";
}
displayForm($fname, $lname, $gender, $comment, $err);
?>
</div>
</body>
</html>



Reply With Quote
!!! I carnt seem to get rid of the text and moke it code!!!

Bookmarks