OK. When you say "write it to a different file" do you mean actually write the information (as a kind of log), or do you want the information to be available to use by the page?
Either way, you need to write some code that processes the data.
If all you want to do is log the information in a file, you can create a form similar to the one I wrote above, and in the action you could put (for example) "log_data.php".
You need then to create a file called log_data.php, which would need to look something like this:
Code: Select all
<?php
//check if the $_POST array is initialised
if(isset($_POST['username'])) {
// open a text file in append mode. If the file doesn't exist, php will
// attempt to create it.
$outfile = fopen('my_log_file.txt', 'a');
// loop through each data in the $_POST array, and write it to the file
foreach($_POST as $field_name=>$field_value) {
fwrite($outfile, $field_name.'='.$field_value.'\r\n';
}
} else {
//$_POST is not initialised, so no data
die("No data submitted");
}
?>
Please note, I haven't tested any of this, and I haven't done any error checking or sanity checking of the data.
Notice that on this page, the $_POST array will contain all the data inputted by the user on their form.