HTML form preview then INSERT using PHP & MySQL

Hello everyone! This is regarding HTML forms, PHP & MySQL.

My Question:

How do you create an html form that goes to a preview screen and then allows the user to move back to the form if they made any errors and corrections are needed or click the send button to submit the form? The form's contents are then inserted into a database table.

The actions I want the user to take are as follows:
1) Fill out form.
2) Press Preview Button (the only button on that page).
3) Look over preview of text entered. (this should be on a new page and appear as text, not text in form fields.)
4a) If user finds mistake in text of Preview, click Edit button (or link or Browser back button) to go back to form and make changes. Then user repeats steps 1 (editing not re-entering data) through 4.
4b) If user does not find mistakes in text of Preview, clicks submit button that INSERTS form data into MySQL table.
5) User gets a new page thats says "thank you. form submitted."

I already know how to INSERT form data into a table and ECHO the data onto a page after the data was inserted, but I can't figure out how to add the Preview in the middle before inserting the data.

Many thanks to anyone who can help me with this!
- Steve 🙂

Just incase you need to know.. my current setup is:
Solaris 2.7
Apache 1.3.3
MySQL Version 3.23.43
PHP 4.1.0 Apache Module

    <?php
    / form.php /
    print "Please fill out the form<br>\n";
    print "<form action=\"preview.php\" method=\"post\">\n";
    print "<input type=\"text" name=\"firstname\" value=\"$f_firstname\" size=\"20\">\n";
    print "<input type=\"text" name=\"lastname\" value=\"$f_lastname\" size=\"20\">\n";
    print "<input type=\"text" name=\"phone\" value=\"$f_phone\" size=\"30\">\n";
    print "<input type=\"submit" value=\"Okay!\">\n";
    print "</form>\n";
    ?>

    <?php
    / preview.php /
    print "Here's a preview of your info<br>\n";
    print "Your first name: $firstname<br>\n";
    print "Your last name: $lastname<br>\n";
    print "Your phone number: $phone<br>\n";
    if (!$firstname || !$lastname || !$phone) {
    print "Hmm...looks like your information is incomplete. Please fill out the form again.<br>\n";
    print "<a href=\"form.php\">go back</a>\";
    }
    else {
    print "<form action=\"form.php" method=\"post\">\n";
    print "<input type=\"submit\" value=\"Edit info\">\n";
    print "<input type=\"hidden\" name=\"f_firstname\" value=\"$firstname\">
    print "<input type=\"hidden\" name=\"f_lastname\" value=\"$lastname\">
    print "<input type=\"hidden\" name=\"f_phone\" value=\"$phone\">
    print "</form>\n";
    print "<form action=\"write2db.php" method=\"post\">\n";
    print "<input type=\"submit\" value=\"Post info\">\n";
    print "<input type=\"hidden\" name=\"f_firstname\" value=\"$firstname\">
    print "<input type=\"hidden\" name=\"f_lastname\" value=\"$lastname\">
    print "<input type=\"hidden\" name=\"f_phone\" value=\"$phone\">
    print "</form>\n";
    }
    ?>

    <?php
    / write2db.php /
    / now you can INSERT $f_firstname, $f_lastname and $f_phone into your table..
    /
    ?>

      Write a Reply...