Click to See Complete Forum and Search --> : to use PHP to make a form


dummyagain
June 5th, 2004, 07:58 AM
I am making a php form that will collect some data typed by the user.... however, i don't know how to get those data output to a file that in the web server

can anybody help or send me some examples for illustration


thanks

khp
June 5th, 2004, 11:12 PM
Use fopen to open a file, then use fwrite to write something to it.

http://www.php.net/manual/en/function.fopen.php

bobo
June 11th, 2004, 10:29 AM
and if your on a unix system don't forget to set the right permission to write to the file

bobo
June 11th, 2004, 02:17 PM
open a file:

if(!($fp = fopen("./data.txt", "r"))) die ("Cannot open the file");

example of writing to a file for a simple hit counter:

<?php
$counter_file = "./count.dat";
if(!($fp = fopen($counter_file, "r"))) die ("Cannot open $counter_file.");
$counter = (int) fread($fp, 20);
fclose($fp);
$counter++;
echo "You're visitor No. $counter.";
$fp = fopen($counter_file, "w");
fwrite($fp, $counter);
fclose($fp);
?>