I'm pretty new to PHP( and this forum!) I like it, it looks like PHP have got a lot of power, but not when you get stuck, like me! I'm (trying) to code one of those "Write News" script found at various decent webpages. But I'm having problems with the part where PHP shall write/read something to/from a .txt file, I just cannot get it to work what-so-ever.
The PHP Script is attached.
And for those lazy of you out there (like me):
The WRITE NEWS part, where you actually write the news into a form and post it.
<html>
<head>
<title>Write News</title>
</head>
<body>
Write a news-item here:<br>
<form method="post" action="news_send.php">
<textarea name="newsitem" cols=50 rows=10 wrap=virtual>
</textarea><br>
<input type="submit" name="submit" value="Post News">
</form>
</body>
</html>
This is the part where the user input is SAVED INTO A TEXT FILE.
<?php
if ( ($newsitem == "") ) {
header("location: [url]http://localhost/news_write.php[/url]");
exit;
}
$newsarchive = "http://localhost/newsarchive.txt";
$writepointer = @fopen($newsarchive, "a") or die("Error! Can't open file.");
@fwrite($writepointer, $newsitem) or die("Error! Cant write to file.");
fclose($writepointer);
$msg = "News stored!";
?>
<html>
<head>
<title>Send News</title>
</head>
<body>
<?php echo "$msg";?>
<a href="http://localhost/news_display.php"> Show News!</a>
</body>
</html>
-----------------------------------------------------------
And this is the last part where the NEWS ARE LOADED FROM THE TEXT FILE AND DISPLAYED TO THE USER
<?php
$newsarchive = "http://localhost/newsarchive.txt";
$readpointer = @fopen($newsarchive, "r") or die("Feil! Kan ikke åpne fil");
$contents = @fread($readpointer, filesize($newsarchive));
fclose($readpointer);
?>
<html>
<head>
<title>Display News</title>
</head>
<body>
<h4>News for today:</h4><p>
<?php
echo "$contents";
?>
</body>
</html>
Thank You!
I would love all the help i could get!
Thanks in advance!
BTW: remember that im a newbiw, so explain things in an easy way.
=)