The date is $date1 and the current time is $date2

"; // Let's create a variable that contains--as one long text string--all the information // we wish to save for the user. $stringData = "\n" . $date1 . "," . $date2 . "," . $v01 . "," . $v02 . "," . $v03 . "," . "endline"; // Finally open the file, place the data within, then close the file. $myFile = "testFile01.txt"; // set the datafile name $fh = fopen($myFile, 'a') or die("can't open file"); // open the file a = append fwrite($fh, $stringData); // place the data in the file fclose($fh); // close the file /* Note: I always place the text "endline" at the end of a row of data. This is habit, but is not necessary. Doing this, however, will make it easy to check whether data are being imported correctly. (If they are, then the word "endline" will appear in the final column for all users.) Additional note: The use of \n allows us to "hardcode" a line break (or line feed) into the file. This is a common ASCII way of coding line breaks in text files. This ensures that the user's data are printed to a unique row and that the next person's data will not appear in the same row of the text file. We start by printing the ASCII linebreak so that the current entry will appear on a new row. Notice that we are using concatenation to string together all the data we wish to store for the user, and separating each piece of information with a comma. We could use an alternate delimiter if we wish. $fh is short for "file handle" and is a way of calling a specific file operator via shorthand. */ print "

Congratulations. You just saved some data to the textfile. Refresh the page to see the file grow!

"; #----------------- /* We can also read data from the file and use it. */ // Read data from file to compute sample summaries $myFile = "testFile01.txt"; $fh = fopen($myFile, 'r'); // r = read $theData = fread($fh, filesize($myFile)); fclose($fh); // Show contents of data file for illustration purposes print "Here are all the data thus far:

"; echo "
$theData


"; ?>