Forum Moderators: coopster

Message Too Old, No Replies

append form info to txt file using PHP

         

MarkA50

11:52 am on Nov 21, 2003 (gmt 0)



Hi, I'm looking for a PHP script whereby the information that is submitted on a HTML form is appended to text files with each entry date and time stamped.
Can anybody help? Many thanks.

dreamcatcher

1:07 pm on Nov 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World MarkA50.

Its not too hard to write the contents of a form to a text file. Once your form is submitted, do something like:


$date = date("d-m-y H:i:s ");
$server_path = "/your/server/path/"; //Path to log directory
$log_entries = $date. "¦" .$_POST['name']. "¦" .$_POST['comments']. "¦" .$_POST['email']. "¦\n";

$fp = fopen($server_path . "log/form.log", "w+") or die("ERROR! Cannot create 'form.log' file.");

if ($fp!= false)

{

fwrite($fp, $log_entries);
fclose($fp);

}

Think something like that would work. CHMOD the /log/ directory to 777.

:)