Well, in my opinion using session variables is a bit better. It makes it completely transparent to the user. (Because really, a user only has to view the source of the webpage to figure out what's going on when you use hidden fields.)
So, to give a complete example, you can do this:
Page 1
<!-- Filename: page1.php -->
<html>
<head>
<title>Page 1</title>
</head>
<table width="400" cellpadding="0" cellspacing="0" border="0">
<form action="page2.php" method="post">
<tr>
<td>
Email:
</td>
<td>
<input type="text" name="email" size="50">
</td>
</tr>
<tr>
<td>
Comments:
</td>
<td>
<textarea cols="50" rows="6" name="comments"></textarea>
</td>
</tr>
<tr>
<td colspan="2" align="middle">
<input type="submit" name="formprocess" value="Submit Form">
</td>
</tr>
</form>
</table>
Page 2
<?php
// Filename: page2.php
if($_POST['formprocess'])
{
// Start the session.
session_start();
// Checking incoming form data...
if((!$_POST['email']) || (!$_POST['comments']))
{
echo "Oops, looks like you missed some fields!";
// If the email address is blank let them know.
if(!$_POST['email'])
{
echo "You forgot to input an email address, input it below.";
}
// If the comments section is blank let them know.
if(!$_POST['comments'])
{
echo "You forgot to input your comments. Input them below.";
}
// Include the form again.
include "page1.php";
// Exit the script.
exit;
}
// Assign the post variables to session variables.
$_SESSION['email'] = $_POST['email'];
$_SESSION['comments'] = $_POST['comments'];
// Show them the preview of what they just submitted.
?>
<html>
<head>
<title>Page 2</title>
</head>
<table width="400" cellpadding="0" cellspacing="0" border="0">
<form action="page3.php" method="post">
<tr>
<td>
Email:
</td>
<td>
<?=$_POST['email']?>
</td>
</tr>
<tr>
<td>
Comments:
</td>
<td>
<?=$_POST['comments']?>
</td>
</tr>
<tr>
<td colspan="2" align="middle">
<input type="submit" name="finalsubmit" value="Add to Database">
<form action="page1.php" method="post">
<input type="submit" name="nosubmit" value="Cancel">
</form>
</td>
</tr>
</form>
</table>
<?php
// Close the if structure
}
// This is incase they somehow got to this page without using the previous form.
else
{
echo "Oops, looks like you're somewhere you shouldn't be!";
}
?>
Page 3
<?php
// Filename: page3.php
// Checking to make sure that they've come from the previous form.
if($_POST['finalsubmit'])
{
// Start the session.
session_start();
// Include your database config file.
include "config.php";
// Formulate and execute the query using session variables to insert the data.
$sql = "INSERT INTO table VALUES ('".$_SESSION['email']."','".$_SESSION['comments']."')";
mysql_query($sql) or die ("Could not execute query.");
// Query was successful, so now we just let them know.
?>
<html>
<head>
<title>Page 3</title>
</head>
Form submitted successfully!
<?php
// Close the if structure.
}
// If they've got here by other means, we'll let them know.
else
{
echo "Oops, looks like you're somewhere you shouldn't be!";
}
?>