Page 1 of 1

news/update

Posted: Thu Mar 25, 2004 1:49 am
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 !

Posted: Thu Mar 25, 2004 10:44 am
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.

Posted: Thu Mar 25, 2004 11:37 am
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)