PDA

For continued disscussion on this topic : Writing the form content to a log file in a certain format....



George W. Bush
06-02-2001, 10:25 PM
I would like to find some information that will allow me to do such a thing. I do not undestand the commands that open the text file and write the form information into it. I am interested in having one log file where inside it I would have all the information.

In this script, there are 2 files. The form and a text file where the information is written to.

The form writes fine to the text file. But it writes the contents of each field on one line and it throws a tab between them so you can read them easier. The names of each field are NOT written, only the content. I would also like to write the names of the field followed by the content that was inputed in a format as:

LOGIN:
PASSWORD:
FULL NAME:
URL:

Right now it writes the content only in a straight line separated by a tab. But I am having problems adding the field names as above then have the content follow it.

The script is easy to go through, yet I do not see what I am missing...


1) The small form with PHP that writes to the text (result.txt) file is here and it is very small and does the work well, except what I would like to accomplish:

<HTML>
<HEAD>

<?
$file_name = "result.txt";
?>

<BODY>

<?
if ($insert) {

// check existence of file (or try to create it)
$try = touch($file_name);
if (!$try)
{
echo "Sorry file can't be opened";
exit;
}

// content from form inserted it into an array
$input = array ($login, $password, $fullname, $url);

// tabs inserted between the form element content
$output_line = implode ($input, " ")."\n";

// open the file (get a file pointer)
$output_stream = fopen($file_name, "a");

// dump the string into the text file
$result = fputs ($output_stream, $output_line);

// close the file pointer
fclose($output_stream);
?>

<?
//exit and the first bracket is closed here
exit;
}
?>

<FORM METHOD="POST" "<? echo $PHP_SELF; ?>">
....the form then comes here....
</FORM>

</BODY>
</HTML>

Very small but I cannot tell it to write the field names (headings) and content in a vertical format like:

LOGIN:
PASSWORD:
FULL NAME:
URL:

and not horizontal with tabs.

I would appreciate your extertise in this. Thank you once again!

jonsteele
06-02-2001, 10:45 PM
Try changing this:



// content from form inserted it into an array
$input = array ($login, $password, $fullname, $url);

// tabs inserted between the form element content
$output_line = implode ($input, " ")."\n";

// open the file (get a file pointer)
$output_stream = fopen($file_name, "a");

// dump the string into the text file
$result = fputs ($output_stream, $output_line);

// close the file pointer
fclose($output_stream);


to this:



// content from form inserted it into an array
//$input = array ($login, $password, $fullname, $url);
//don't need array.

// tabs inserted between the form element content
$output_line= "LOGIN:\t$login\nPASSWORD:\t$password\nFULLNAME:\t$fullname\nURL:\t$url\n\n";

// open the file (get a file pointer)
$output_stream = fopen($file_name, "a");

// dump the string into the text file
$result = fputs ($output_stream, $output_line);

// close the file pointer
fclose($output_stream);


The $output_line variable contains the info which is being written.
You don't even need the array.

Jon.

P.S. Did you want this to be a new thread?

George W. Bush
06-02-2001, 11:17 PM
Oh, yes... can you do that. I am sure some individuals would like to read about it.

George W. Bush
06-05-2001, 12:30 AM
Yes, people... get that script and try it out as it works fine. Thanks a bunch to js...

George W. Bush
06-12-2001, 07:51 PM
One more question regarding this issue. So, as the script above shows one can write all the fields to a text file. Now the question is, can each entry have a number starting with 1, 2, 3 and so on. I am assuming that if there are 145 entries one would have to count them each, and that is painiful. So, I was thinking that perhaps before the first field is written, if the number was written would be nice.

jonsteele
06-12-2001, 09:12 PM
You'd need to detect the last written log, then add one to it. You'd have to use fread(). Or you could store the number of entries logged somewhere else, then add one to it.