Hello, i;m makeing a news script and most of it works but i am haeving trubble getting it to stop after 3 headlines have been made so i made a script that added a number to newscount.txt and when news count.txt was to big ther would be no news.
heres my code
php:
<?php session_start();?>
<meta http-equiv="refresh" content="4 ;URL=index.php" />
<?php
if (isset($_SESSION['username'])) {
$name = $_SESSION["username"];
if ($name == "admin") {
$headline=$_POST['headline'];
$user=$_POST['user'];
$msg=$_POST['msg'];
$time=date("H:i dS F");
$newscount="newscount.txt";
$handle=fopen($newscount, "r") or die("Error");
$c=fread($handle, filesize($newscount));
fclose($handle);
if ($c < 2) {
$filename="news.txt";
$handle=fopen($filename, "r") or die("Error");
$old_content=fread($handle, filesize($filename));
fclose($handle);
$data = "<b>$headline</b><p>$msg<br /><br />Posted by $user at $time<br /><br /><br />";
$final_content=$data.$old_content;
$handle2=fopen($filename, "w") or die("Error");
$finalwrite=fwrite($handle2, $final_content);
fclose($handle2);
echo "redirecting you.....";
$c++;
if ($c == 0) {
$c=1;
}
$file=fopen($newscount,"w") or die("Error");
fwrite($newscount,$c);
fclose($file);
}
}
}
else {
echo "Your not a Admin and only admins can post news.";
}
?>
--------------------------------------------------------------------------------
problem is nothign is being writen to newscount.txt, if ther is somthign in ther is it over writen with nothing and if thers not a i get a error saying
Warning: fread() [function.fread]: Length parameter must be greater than 0. in C:\Abyss Web Server\htdocs\news.php on line 17
redirecting you.....
Warning: fwrite(): supplied argument is not a valid stream resource in C:\Abyss Web Server\htdocs\news.php on line 41
thats what i get when newscount.txt is empty but like i said if i write somethign in it it gets over wirten with nothing (blank)
so i am always gettting this error
Warning: fwrite(): supplied argument is not a valid stream resource in C:\Abyss Web Server\htdocs\news.php on line 41
line 41: fwrite($newscount,$c);