Ok, just to get a better feel for this I created 3 pages from your code, starting with formtest.php (index.php in your example),
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Comment Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><font size="+1">Comments Demo:</font></p>
<table width="80%" border="1" cellspacing="0" cellpadding="5">
<tr>
<td align="left">
<?php
if ($file = @file_get_contents("comments.phpdata")) {
echo $file."\n";
}
else {echo "Sorry, but no comments were found.";}
?>
</td>
</tr>
</table>
<p><a href="formtest2.php">Add Comment</a></p>
</div>
</body>
</html>
formtest2.php (your add.php)
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Add Comment Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div align="center">
<p><font size="+1">Add Comment Demo:</font></p>
<form name="form1" method="post" action="formtest3.php">
Name: <input name="name" type="text"> -- Email: <input name="email" type="text"><br>
<textarea name="comment" cols="60" rows="10"></textarea><br>
<input type="submit" value="submit"> - <input type="reset" value="reset">
</form>
<a href="formtest.php">Back</a>
</div>
</body>
</html>
and formtest3.php (your sent.php)
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
$filename = "comments.phpdata";
if ($name = stripslashes($_POST['comment'])) {
$comment = str_replace("<","<",$comment); //security
$comment = str_replace(">", ">", $comment); //security
if ($email = stripslashes($_POST['email'])) {
$email = str_replace("<","<",$email); //security
$email = str_replace(">", ">", $email); //security
$email = "<a href=\"mailto:".$email."\">".$email."</a>";
}
else {
$email = "(No Email supplied.)";
}
$name = stripslashes($_POST['name']);
$name = str_replace("<","<",$name); //security
$name = str_replace(">", ">", $name); //security
if (!$name) {
$name = "<i>Anonomous</i>";
}
$hr = "";
if (strlen(@file_get_contents($filename)) > 0) $hr = "\n<hr>";
$add = $hr."Posted by: <b>".$name."</b> -- ".$email."<br>".$comment;
$comments = @file_get_contents($filename).$add;
$file = @fopen($filename, "w+");
@fwrite($file, $comments);
@fclose($file);
$message = "Your comment was successfully added.<br>Redirecting to formtest.php";
}
else {
$message = "You either entered no data or it was entered incorrectly.<br>Redirecting to formtest.php";
}
?>
<html>
<head>
<title>Comment Added Demo</title>
<meta http-equiv="refresh" content="3;url=formtest.php">
</head>
<body>
<div align="center">
<p><font size="+1">Comment Added Demo:</font></p>
<?php echo $message; ?>
</div>
</body>
</html>
not sure if I was supposed to, but I created a blank file "comments.phpdata" and uploaded it as well.
All seems ok except that it displays nothing when it redirects back to the first page, I must have missed something.. check it out here
Bookmarks