SUCCESS!!!
Ok sweet, that totally worked. I had to clear my cache.
ok, one last thing. I need the user to be sent to a success page. right now page 5 posts to process.php. which ultimately is a blank page for the user.
I already have a success.php page. so my question is, should I just put the processing script at the top of success.php or should I still go to process.php and then put some sort of redirect in it that sends the user to success.php?
For future viewers of this post, here is all the working code we used for passing form values through several pages and then finally posting into a database after completion of form:
Use this code in all form pages except your first form page:
<?php foreach ($_POST as $key => $val) {
echo '<input type="hidden" name="' . $key . '" value="'
. htmlentities($val, ENT_QUOTES) . '" />' . "\r\n";
}
?>
place the code above just inside your form begin tag. example:
<form method="POST" action="employment3.php" enctype="application/x-www-form-urlencoded" name="employment_form" id="employment_form">
<?php foreach ($_POST as $key => $val) {
echo '<input type="hidden" name="' . $key . '" value="'
. htmlentities($val, ENT_QUOTES) . '" />' . "\r\n";
}
?>
Then in your final processing script use the code below. change the database values to match your own:
<?php
mysql_connect("myhost", "myusername", "mypass") or die(mysql_error());
mysql_select_db("mydatabase") or die(mysql_error());
if(!empty($_POST))
{
$first="";
$second="";
$insert="INSERT INTO mydbtable (";
foreach ($_POST as $key => $var)
{
if($key!="submit")
{
$first.=$key.","; // <----- use ` in field names if you want to make this better
$second.="'". mysql_real_escape_string($var)."',"; // <----- use ' on values.
echo '<input type="hidden" name="' . $key . '" value="' . htmlentities($var, ENT_QUOTES) . '" />' . "\r\n";
}
}
$query=$insert.$first.") VALUES (".$second.");";
$query=str_replace(",)",")", $query) ;
mysql_query($query) OR die(mysql_error()) ;
}
?>
And that's what worked for us!