simple post question i think

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Atomic Monkey
Forum Newbie
Posts: 7
Joined: Sun Apr 20, 2003 11:19 am
Location: Arkansas
Contact:

simple post question i think

Post 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?
wallabee
Forum Newbie
Posts: 20
Joined: Mon Apr 21, 2003 10:01 pm

Post 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.
Post Reply