Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to log to unique files?

Status
Not open for further replies.

may1hem

Programmer
Joined
Jul 28, 2002
Messages
262
Location
GB
Hi, I've created a form on a Web page which allows a user to make comments and state any problems/issues.

At the moment, the forms logs the user issues to one long text file. I'd like it to log the issues to separate text files.

Any ideas how I can log each problem to separate text files and ensure that I don't overwrite any of the existing text files?

Here is the code so far, which logs to only 1 file so far. By the way, my Web space uses only PHP3.

ProcessForm.PHP:
-------------------
<?php

$myFileHandle = fopen('ZaznamyOProblemoch.txt','a') or die(&quot;can't open file&quot;);

if (-1 == fwrite($myFileHandle,date(&quot;D j M Y g:i a&quot;).chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtCompany.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtAddress.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtPhoneNumber.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtEmail.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtComments.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtProblem.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtProblemFound.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtReason.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtDateOfProblem.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,$txtProblemCaused.chr(10))) { die(&quot;can't write data&quot;); }
if (-1 == fwrite($myFileHandle,&quot;-----&quot;.chr(10))) { die(&quot;can't write data&quot;); }

fclose($myFileHandle) or die(&quot;can't close file&quot;);

?>
-------------------

Thanks for your suggestions,

May
 
the only Problem I can see here is if there is a 1,000 or even 10,000 forms filled in then your data is going to get seriously disorganized, therefore I think that you should seriously consider putting all this information into a DBMS (database management system) such as MySQL, this will allow your website to grow yet the information will still be organised, if you insist on following your current path then a simple way would be to use a separate text file to hold a number and then each time a new form is made just get the number and increment it by one then call the file 'ZaznamyOProblemoch + number + .txt' after this is done overwrite the file with the new number.

To err is human, to completely mess up takes a computer. [morning]
 
Thanks for your advice csniffer.

May
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top