Jump to content

basic news system help


zeth369

Recommended Posts

I'm very new to php, I just started learning it about a week ago.  I'm just starting to get a hang of the basics and i decided to try to create a basic news system without using mysql.

 

basically what im trying to do is be able to use a form, have the info from the form go into a file, and read the file and print it to another page.  The problem im having is that every time i refresh the page, it prints it again and again and again.  please help!!

 

form page

<html>
<body>

<form method="POST" action="main.php">

Author: <input type="text" name="author" />
<br>
News: <input type="text" name="news" />
<input type="submit" value="submit news" />

</form>
</body>
</html>

 

code to print news:

<?php
$author = $_POST["author"];

$zeth = file_put_contents("test.php","<center>Author: " . $author . "<br>" . $_POST["news"] . "<br><hr><br></center>", FILE_APPEND);

?>

 

also:

<?php

$file = filesize("test.php");

$news = file_get_contents("test.php");

$finalnews = wordwrap("$news",75,"<br>");

print $finalnews;


?>

Link to comment
https://forums.phpfreaks.com/topic/158187-basic-news-system-help/
Share on other sites

delete the file you are writing to (clean start), and post to it again. How many news items do you have? should be one...

Post a new one. How many do you have? should be two...

do that a few times and see what you get and let us know.

 

btw, I suggest this code for saving:

<?php
if(isset($_POST['author'])){
$author = $_POST["author"];

$zeth = file_put_contents("test.php","<center>Author: " . $author . "<br>" . wordwrap($_POST["news"], 75, "<br />") . "<br><hr><br></center>", FILE_APPEND);
}
?>

and this code to output the file's content:

<?php

$file = filesize("test.php");

$news = file_get_contents("test.php");

print $news;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.