Link to home
Create AccountLog in
Avatar of alainbryden
alainbrydenFlag for Canada

asked on

How can I take simple form information and write it to a file

I need some sample code to get me started or something. I have no idea how to take web form information and store it in a permanent file so that it can be retrieved later.

For example, if someone types "Hello World" into a form, and clicks "submit", I want to be able to create a file on my server ftp called "Results.txt" which contains "Hello World", or whatever was typed.

From this basic example I could proceed to do what I really want:

In the end result, I want people to be able to take an online study, which is located at http://whitelab.biology.dal.ca/Pilot_whale_comparisons/compare_calls.php?type=Pulsed%20Calls, where they identify whale calls, and I want to append each trial result to a file named after that persons IP address or something unique, so that it can later be retrieved, compiled and analyzed manually.

The server has all asp, php, etc installed, so any method of accomplishing this will probably work. Of course, it should fly in both IE and Firefox. I'm currently using php to create my form, I'll upload that file 9in txt format) so you can see what php is doing before generating the html.

Thank you very much for any sample code or useful information you can provide. It's very hard to find appropriate tutorials online for what I wish to do when I know so little already.

--
Alain
compare-calls.txt
Avatar of rowejd
rowejd
Flag of United States of America image

I'm in the middle of showing a guy how to do this exact thing -- check out this solution with code and links and all:

https://www.experts-exchange.com/questions/23221413/Is-it-possible-to-create-an-html-doc-including-form-entries-with-php.html
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I agree with hielo that a database is the way to go.  But if you have a specific reason for needing a file to be written, then fwrite is the way to go.  In my example to the other fellow in that link--you'd just change the extension from .html to .txt -- pretty cool stuff.
Avatar of alainbryden

ASKER

I am in the process of trying to set up an output using fwrite, but discovered that the server administrator has disabled the creation of files on the server by scripts, so I will have to ask him to lift this restriction before I can continue. It shouldn't be more than a week, when he gets back from his conference.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Any update on this?  Need more info or is this enough to assign points & close out the question?
I won't abandon this question, don't worry, it's just not easy to get an audience with whoever wants to take responsibility for the server.
After some troublesome dealings I was told that I can "do it myself" so far as permissions go, so using the TORCH ssh thing I set the folder permissions of Results/ to 777 (full read write and execute for all users) yet I'm still getting the same permissions error message:

Warning: fopen(Results/test.txt): failed to open stream: Permission denied in /home/whitelab/public_www/Pilot_whale_comparisons/whistles_or_pulsed_calls.php on line 27
Cannot open file (Results/test.txt)

You can see the error for yourself here: http://whitelab.biology.dal.ca/Pilot_whale_comparisons/whistles_or_pulsed_calls.php

baisically, I've set permissions on the linux environment, this is something not related to the directory permissions, it's something else...
The server administrator said her reset some access control lists and now the suggested code works fine. Thank you for your input.