Hey, im trying to figure out how to store date from a form into a .txt file, but so far it aint going that good...
So i was hoping that some of you could help me.
It´s really pretty simple, all i want to, is to set up a html form that users fill out, and then when they submit the form it stores the data in a txt file, pretty much like form mail, just with out mailing it.
i have this code:
<html>
<body>
<?
if (isset($_POST["confirm"]))//posted?
{
//php must have write-access in this directory
$fp=fopen("data.txt","wb");//overwrite existing text file
fwrite($fp,var_export($_POST,TRUE));//write post-data
fclose($fp);
}
?>
<form action='<?=$_SERVER["PHP_SELF"]?>' method="post">
name<input type="text" name="name"><br>
city<input type="text" name="city"><br>
telnr a<input type="text" name="telnr[0]"><br>
telnr b<input type="text" name="telnr[1]"><br>
<input type="submit" name="confirm">
</form>
</html>
BUT the problem is, that every time you submit something, it over writes the old data in the .txt file, it should add another line, not delete whats all ready there. and the out come of the file looks like this:
array (
'name' => 'myname',
'city' => 'mycity',
'telnr' =>
array (
0 => 'my number A',
1 => 'my number B',
),
'confirm' => 'Submit Query',
)
Maybe it was possible to make it look like
myname
mycity
my number A
my number B
i hope some one can help me with this, since i can´t figure it out.
Thanks in advance
Maller