Click to See Complete Forum and Search --> : Simple form input to txt file


kwertyuk
10-11-2008, 01:52 PM
Hi,

I am a complete novice when it comes to PHP. I have a text field on my webpage and when the user clicks submit I want the contents to be written into a .txt file.

I googled a few ways of doing it but they all replace the contents of the .txt file whereas I want the form input to be added onto the end of the contents of the .txt file.

And I would want each entry to be ended with a ";" to seperate them.

The contents of the .txt file would appear something like this:

"input1 from form; input2 from form; input3 from form; ... etc"


Any ideas on how i could do this?

Cheers, Dave

ratcateme
10-11-2008, 03:28 PM
if you make a php script that formats the form data something like this
$formdata = $_POST['formfield1'].' '.$_POST['formfield2'];
then write it to the file something like this
$filename = "formdata.txt";
if(file_exists($filename)){
$fh = fopen($filename,"a"); //open file 'a' for append
fwrite($fh,";".$formdata);
}else{
$fh = fopen($filename,"w") //'w' for write and create
fwrite($fh,$formdata);
}
fclose($fh);
but if you delete the contents of the file but don't delete the file then you will get a ; in front of the first entry

Scott.

kwertyuk
10-11-2008, 06:35 PM
Cheers for that. as far as I can tell from my limited experience that should work.

I am having a problem though. When i submit the form to my php file i get an error page:

"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request. ..."

Any ideas why this is happening. I have changed all my permissions to 777 (a problem I found had caused similar issues) but still not working.

Any ideas?

Cheers, Dave

ratcateme
10-11-2008, 07:45 PM
internal server errors are generally 500-505 these are to do with your webserver not php are you trying to run php as a CGI module?
can you run any php scripts on the server?

Scott.

kwertyuk
10-12-2008, 08:10 AM
As I said, I'm a total beginner at this.

So anyway i tried loading a simple echo php script onto my server and yes this had an internal error as well. So you were right.

I assumed that php would go in the public_html folder like everything else. But there is a separate php folder.

so now i have to work out how to use that. lol.

dave