spinPHP

Form To File Example

This is an example on how to extract the values that are entered in an HTML form and save these into a tab-delimited text file on the server. The date & time and the IP-address of the user submitting the form are also stored in the file.

You can open this page in PageSpinner to view the PHP code that performs these actions.


Enter some text in the following fields and click the Submit button:

Comment:
Name:  
Thank you, have entered the following:
"); echo("Comment: ". $theComment ."
"); echo("Name: ". $theName ."

"); $fileName = "mydatabase.txt"; $file=fopen($fileName,"a"); // Open the file with "a" access to append data fputs($file, $theComment."\t"); // Append the comment + a tab to the end of the file fputs($file, $theName."\t"); // Append the name + a tab to the end of the file fputs($file, $_SERVER['REMOTE_ADDR']."\t"); // Append the IP address + a tab to the end of the file fputs($file, date("m/d/y H:i:s") ."\n"); // Append a timestamp + a linefeed to the end of the file fclose($file); // Close the file echo("

Your comment has been stored in the database.

"); echo('

View the database file

'); } ?>

See:
Form Access Introduction for info on how to process the data in the form
File Handling Introduction on how to store data in a text file
Displaying current date and time on how to get the current date and time
IP-Address Detection on how to get a users IP-adress


This PHP code example is copyright © 2002-2003 Optima System. All rights reserved worldwide. Unauthorized distribution prohibited. SpinPHP™ User License.