recore684
05-26-2005, 09:24 PM
The functions I am using for my guestbook are not working properly and I was wondering if someone could point me in the right direction.
<?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";
?>
<?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;
}
?>
<?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";
?>
<?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;
}
?>