Jump to content

Posting To A Text File


smy101

Recommended Posts

Ok, so I have a basic HTML form set up to be processed via "formprocessor.php"

"formprocessor.php" collects the user submitted data and emails it to the appropriate email address depending on which person is selected on the form.

My question is this:

I would like to have the data posted to a text file simultaneously in order to log each instance of the form being submitted.

So, say a person fills out the following on a form:

Name:  John Doe
Email:  [email protected]
Phone:  123-456-7890
Address:  123 John Doe Street

Then they select the appropriate representative to send it to via a drop-down list on the same form, so lets say they select to send it to "Bob Doe"

The form would then email "Bob Doe" the collected data.

I would like to have it also simultaneously post a new entry to a basic text file (or equivalent).

So everytime they select "Bob Doe" it also writes a new entry with the same info to "bobdoe.txt"
If they select "Jane Doe" it would write it to "janedoe.txt" and so on and so forth.

Can this be done simulatenously by using the same submit button that is used to process the email script?  Also, if there was a way for it to precede each new entry by a single-digit increasing number that would be great, too.

Im guessing this can be done using the fopen, fwrite or something similar, but I cant get it figured out.

Any help is greatly appreciated.  Thanks in advance.  ???
Link to comment
https://forums.phpfreaks.com/topic/34199-posting-to-a-text-file/
Share on other sites

The hardest thing will be the counter. If you ment a counter just for that file, that's much easier, but still a little complex.

You want fopen and fwrite. fopen provides the "handler", then fwrite will append your text to the end of the file.
http://us2.php.net/manual/en/function.fwrite.php

If you still want to do the counter, you have to read the file as well, and search it for the previous count. It usually helps to specially mark the count (like !!32!!), so that it's easily found.
http://us2.php.net/manual/en/function.fopen.php


Doing this stuff with a database is much easier.
Thanks, but I'm having problems with how to write the code to merge with the current function of the form.

Would you, or anyone else, mind showing me how I need to write the code?

I can live without the numbering thing, but I need to get the text log file set up.


Thanks again!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.