news/update

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
saviiour
Forum Newbie
Posts: 7
Joined: Fri Feb 27, 2004 1:11 pm

news/update

Post by saviiour »

Whats up ppl !

Got a small prob. So i call for the best of yall at this forum. :D

Basically this what i want to do:
- I want create a system/procedure for a user who updates information alot on their website.

- You got two pages:
- main.php
- form.php

THe main.php file is the main file that any user see's. It also includes teh "include statement". Which is not a problem.

The form.php is the page. That the admin of the site can access. WHere whatever the admin inserts into the text box. That information should be collected, and written into the txt file.

So when you view main.php The information should be updated.

Below is the code that i generated. Now ppl keep in mind, that i just picked up php. So go easy. Also i want to use php on this web project i got my self into 8)


<html>
<head>
<title>form</title>
</head>

<body>

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

<textarea name="news" wrap="VIRTUAL" cols="40" rows="10"></textarea>

// open file if not there create file

<?php
$toFile = fopen("news.txt", "w");

// write to file

fputs($toFile, "$news");

// close file

fclose($toFile);
?>

<input type="submit" name="submit">

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

any help is appreciated it.....thx !
User avatar
werlop
Forum Commoner
Posts: 68
Joined: Sat Mar 22, 2003 2:50 am
Location: /dev/null

Post by werlop »

Hi there, welcome to the forum!

I would suggest you take a look at using a MySQL database instead of text files to store the information, it would be easier in the long run, as you would have to think about delimeters to seperate stories in your text file.

Have a look in the php for info on MySQL.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

But if you want to do it this way, you are going to need another page. You have the first page with your text box which will post the data put into the text box to the second page, which is where PHP can get at it. See, php is server-side so once the page is up on the users screen, thats it, php is done until the nest page. So you can't get the data from the text box on the same page the textbox is on (unless you post to itself, but either way it has to be posted before you can get it)
Post Reply