displaying the whole file
Posted: Tue Apr 29, 2003 7:03 pm
Ok, so I've set up my system to write to a .txt file then display it on the main page. However, it only displays the last entry and does not display the entire file. Here's the code:
post.html
<form action="index.php" method="POST">
Input News: <input type="text" name="news" />
Input your forum name: <input type="text" name="posted" />
<input type="submit">
</form>
index.php
<?
if($HTTP_SERVER_VARS['REQUEST_METHOD'] == "POST"){
$newsinfo[0] = $_POST['news'];
$newsinfo[1] = $_POST['posted'];
$file = fopen("news.txt",'a');
fwrite($file,$_POST['news'] . "|" . $_POST['posted'] . "\n");
fclose($file);
} else {
$farray = file("news.txt");
$newsinfo = split("\|",$farray[(sizeof($farray)-1)]);
}
echo "News: " . $newsinfo[0] . "<P>Posted by: " . $newsinfo[1];
?>
Obviously the two txt files are new.txt and posted.txt. I suppose my question is how do I solve the problem of not posting the entire .txt file?
post.html
<form action="index.php" method="POST">
Input News: <input type="text" name="news" />
Input your forum name: <input type="text" name="posted" />
<input type="submit">
</form>
index.php
<?
if($HTTP_SERVER_VARS['REQUEST_METHOD'] == "POST"){
$newsinfo[0] = $_POST['news'];
$newsinfo[1] = $_POST['posted'];
$file = fopen("news.txt",'a');
fwrite($file,$_POST['news'] . "|" . $_POST['posted'] . "\n");
fclose($file);
} else {
$farray = file("news.txt");
$newsinfo = split("\|",$farray[(sizeof($farray)-1)]);
}
echo "News: " . $newsinfo[0] . "<P>Posted by: " . $newsinfo[1];
?>
Obviously the two txt files are new.txt and posted.txt. I suppose my question is how do I solve the problem of not posting the entire .txt file?