You should probably do it very similar to this 🙂
<?php
// Here we check if the form has been submitted
if(isset($_POST['submit'])) {
// If it has we start doing this stuff
// Now we set our variables
$directory = "c:/path/to/directory/";
$filename = $_POST['givenname'].$_POST['surname'];
// Open the file (If it doesn't exist, this will create it
$fp = fopen($directory.$filename, "w+")) or die("Could not create file pointer!");
// Here you need to format the data how you want it, the way i have it is an example
foreach($_POST as $k=>$v) {
$data .= "$k: $v\n";
}
// now write it to the file, if it worked tell the user, if not, fail miserably!
if(!fwrite($fp, $data)) {
echo "Writing to file FAILED!!! Oh god no!";
} else {
echo "Success! Nice Bruva!";
}
// and close the file!
fclose($fp);
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="surname" />
<br />
<input type="text" name="givenname" />
<br />
<input type="submit" name="submit" value="Go go go!" />
</form>
NOTE: This is STILL an example, you should customize this to how you need it.
Hope that helps!
Matt