PHP form processing
Posted: Sun Sep 07, 2003 8:04 pm
Ok this is the problem I'm having: This code is the action to an HTML form and it processes information entered for updating a news section. The thing is; it works, but in order for it to save to the 'whatsnew.html' file, you have to hit the refresh button in the browser. Anyone know why this is and what I have to change to fix it?
Thanks for any help!
Code: Select all
<?php
$entrytitle = $_REQUEST['entrytitle'] ;
$entrycontent = $_REQUEST['entrycontent'] ;
$postedby = $_REQUEST['postedby'] ;
$filename="whatsnew.html";
$date = (date("d-m-Y"));
if($entrycontent){ //Append Information to the end of the file, displaying it first
if($entrytitle!="clear this"){
$oldfile=fopen($filename, "r");
$file_content=fread($oldfile, filesize($filename));
fclose($oldfile);
$f=fopen($filename, "w+");
fwrite($f, "<p><strong>$entrytitle</strong><br>\n");
fwrite($f, "$entrycontent</p>\n");
fwrite($f, "<p class="small">Posted By $postedby on $date</p>\n");
fwrite($f, "$file_content\r\n");
fclose($f);
header("Location: index.php");
}
else //Clear all information in the file
{
$f=fopen($filename, "w+");
fwrite($f, "");
fclose($f);
header("Location: index.php");
}
}
?>