Forum Moderators: coopster

Message Too Old, No Replies

writing data from a form into a file

how do i do it?

         

KrazyKid

7:30 pm on May 8, 2005 (gmt 0)

10+ Year Member



I need to write text from a form on a webpage into a file on the server. I was looking in the PHP manual to try to figure it out, but I couldn't. Can anyone tell me how to do this? Thanks

Stormfx

9:07 pm on May 8, 2005 (gmt 0)

10+ Year Member



Set up your form and have it send the data to your write script, say 'write.php' (Or it can be the same script).

In write.php, get info from the $_POST array, such as:

$text = $_POST['text'];

To write the file, there's a lot of ways, but the simplest is:

file_put_contents($my_file, $text);

Of course you'll want to do error checking, etc with it.

You can use [php.net...] to look through the various functions for accessing and writing to files.

KrazyKid

12:58 am on May 9, 2005 (gmt 0)

10+ Year Member



Hi, two questions. Will that overwrite text already in file or append? I need it to overwrite. And...this will sound stupid...how do I have the form send to the script?

KrazyKid

1:13 am on May 9, 2005 (gmt 0)

10+ Year Member



I get this error:

Fatal error: Call to undefined function: file_put_contents() in /opt2/home3/dogfart/public_html/javathing/skateboarders/write_to_news.php on line 10

KrazyKid

2:22 am on May 9, 2005 (gmt 0)

10+ Year Member



Nevermind, figured it all out, thanks

Stormfx

5:47 am on May 9, 2005 (gmt 0)

10+ Year Member



Good luck :)