Forum Moderators: coopster
ryanc
If not then a text file will do. To add the data you will need to use the fopen() command open the file and then the fwrite() command to write the data submitted. To read the submitted data you can use either fread() or fgets() to grab the data and then the trusty explode() to break it apart and at that point you can echo it out to its appropriate place.
Hope that helps.
1. post.htm:
<html>
<body>
<table align="center" border="0" width="600">
<tr>
<td colspan="5"><iframe frameborder="1" noresize height="440" width="600" src="post.php" name="display" id="display" marginheight="0" marginwidth="0">
</iframe></td>
</tr>
<form method="POST" action="post.php" target="display"><tr>
<td align="right">Name:</td>
<td><input type="text" name="name"></td>
<td align="right">Comment:</td>
<td><input size="40" type="text" name="comment"></td>
<td><input type="submit" value="Submit"></td>
</tr></form>
</table>
</body>
</html>
2. post.php:
<?php
$name=$_POST['name'];
$comment=$_POST['comment'];
$post="$name: $comment";
fopen("post.txt"[smilestopper]);
fwrite("post.txt","Posts","$post"[smilestopper]);
fgets("post.txt"[smilestopper]);
explode("post.txt"[smilestopper])
echo "explode()";
?>
3.A blank post.txt
This doesn't work, but am I even close?
Thanks,
ryanc
A) form.html - I changed your action to post.php?add=y so that it will open the file for writing only if data is submitted else it only opens for reading. I also added a javascript reload so that once the form is submitted it reloads the form.html page to include the new entry.
<form method="POST" action="post.php?add=y" target="display" onsubmit="window.location.reload()">
B) post.php -
<?php
//Checks if $add has any value skips if dont and writes if it does
if ($add=="y") {
$name=$_POST['name'];
$comment=$_POST['comment'];
$post="$name: $comment";
$fp = fopen("post.txt", "a");
$write = fwrite($fp, $post ."<br>");
$close = fclose($fp);
} else {
//Opens file for reading only when $add is not set
$fp = fopen("post.txt", "r");
while (!feof($fp)) {
$buffer = fgets($fp);
echo ("$buffer");
}
$close = fclose($fp);
}
?>
I tested it several times and it works fine. Try it now.
Thank you very much for your help, you rock and you sir are a delight.
ryanc