<?php if ($_POST['email']) { /* check whether the file is loading from the post and assign values to the variables */
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$address=$_POST['address'];
$telephone=$_POST['telephone'];
$countfile = "/cgi-bin/countforms.bcnt"; /* define the file containing the count */
$outfile = "/cgi-bin/outputforms.csv"; /* define the file containing the form data, in this case a .csv text file containing 1 row of each form submitted */
$form_id = file_get_contents( $file ) + 1; /* read the last form number and increment */
$fp = fopen($file, 'w'); /* open the couint file and erase the contents */
fputs ($fp, sprintf('%06d',$form_id)); /* put the new count number to the count file
fclose($fp);
$fo = fopen($outfile,'a+'); /* open the output file to append the new data to the end /*
fputs ($fo, "$form_id,$firstname,$lastname,$email,$address,$telephone\n"); /* write the form to the output file */
fclose($fo);
}
else {
$firstname=$lastname=$email=$address=$telephone=" "; /* blank all data fields */
$form_id='id will be generated on submission'; /* information prompt */
} ?>
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post'>
<div>ID= <?php echo $form_id." Please record this number for your records"; ?></div>
Firstname <input type=text name='firstname' value="$firstname" />
Lastname <input type=text name='lastname' value="$lastname" /><br />
Email <input type=text name='email' value="$email" />
Address <input type=text name='address' value="$address" /><br />
telephone <input type=text name='telephone' value="$telephone" /><br />
<?php if (!S_POST['email']) {echo "<input type='submit' name='submit' value='submit' />" ;} else { echo "thank you"; }
</form> <!-- normal html form -->
the form submits to itself, on submission it writes the id number into the id field and displays the data entered in other fields,
I delete the submit button on the post-submit form on this one so that it is not submitted over n over
the number is consecutive
the serial number is a simple file containing a six digit number,
the number is initially set to 000000 when the script is installed
the number is read, incremented and written back to the erased file after the form is validated
in this concept the validation is lousy(nonexistent), twas just to try it out
thanks edwinhermann for the code correction
the new six digit number and the input data are written to the output file and to the browser for the user to read
the output file is .csv comma separated values, the initial content of the file is a comma separated list of the field names
the data fields are written comma separated
excell reads csv as spreadsheets,
today I am doing accounts so Im excell in my head
the data could be sent to mail(), to the user and the site owner, or all of the above.