I was thinking about how to handle this last night and it dawned on me that you could use a cookie (less secure) or a session (harder) to store whether the user had completed the form. You could also put the information they entered into the cookie or session so that the form could be auto-filled with their data. For example,
Page 1:
[php]<?php
if ( (!isset($_COOKIE['form_submited'])) || ($_COOKIE['form_submited'] != "yes")) {
//Show the form
} else {
// (1 )send them on to page three because they have already filled it out. The cookie says so!
header("Location:
http://www.example.com/page3.php");
// (2) or you could just show the form again and populate it with the data they entered:
echo "Name: ". $_COOKIE['name'];
//etc?.
}
?>[/php]
Page 2:
After the data is put into the database create the cookie and put the value "yes" (the form has been sent)
[php]<?php
$result = mysql_query($sql);
if (!$result) { // if the data was not inserted
$value = "no";
} else { // the query was fine so lets set the value to "yes"
$value = "yes";
}
setcookie("form_submited", $value, time()+3600); /* expire in 1 hour */
header("Location:
http://www.example.com/page3.php");
?>[/php]
Again you could also set a whole bunch of cookies for all of the data fields that were on your form so that if the user went back (say there was a DB error) the form would be auto filled in.