Page 1 of 1

simple post question i think

Posted: Sat Apr 26, 2003 6:11 pm
by Atomic Monkey
I'm trying some thing a little bit different. I have made my form for posting new information. Basic code for the form:

<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>

Now in the index.php I've input this string of code:

<?php echo $_POST["news"]; ?>
<?php echo $_POST["posted"]; ?>

I'm sure that i'm probably just overlooking something extremely simple, but obviously once you refresh the page, or go back to it through the browser, anything that you've entered has been erased. How can I make what I enter in the form stay/save onto the index.php?

Posted: Sat Apr 26, 2003 6:42 pm
by wallabee
it's my understanding, for what it's worth, that this can only be done one of two ways: using a text file to save your $news and $posted, or use a database to save your $news and $posted. unfortunately i have yet to be brave enough to try out databasing, but i do know about writing and reading to text files. for obvious reasons, databases are a little more secure, if you're trying to keep prying eyes out.


basic code for writing to a text file (NOTE: This will not work if you just copy and paste it.):

Code: Select all

<?php
$FileName = "data.txt";
$FilePointer = fopen($FileName, "mode");
fwrite($FilePointer, "data to be written");
fclose($FilePointer);
?>
basic code for reading from a text file (NOTE: This will not work if you just copy and paste it.):

Code: Select all

<?php
$FileName = "data.txt";
$FilePointer = fopen($FileName, "mode");
$Data = implode('', file("$FileName"));
echo $Data;
fclose $FilePointer;
?>
That's the basic idea. Look some of the functions up on PHP.net if you need more information. I knew nothing about PHP a few weeks ago, and now I know just a little more than nothing, but just stick with it. It's not hard, and this forum is a great resource. Use it when you need it.