Got to say ... devinemke' right. Can't you fix your code to make that work?
Anyway, I was just about to post this, so you might as well see it.
My way to do this is:
Here's the pseudo-code:
if(/ form_has_been_submitted /)){
// Include your error-checking code here
if(/* form_filled_out_correctly */){
// Re-direct to new page, using header() function
} else {
// Build error message
}
}
HTML starts here, not before ...
// Display error message, if there is one
// Form HTML Here
BUT ... this only works if you want to go to a new page after the error check (Yes).
AND ... if you use the header() function, there can't be ANY html before the header, so the form must be displayed after the above code. (If the form is filled out correctly, the page will be re-directed before the form shows ... exactly what you want.
The problem is this. If you use header(), the only way I know how to get the variables to the new page would be to build the post array in a string ...
foreach($_POST as $key=>$value){
$my_query[] = $key.'='.$value;
}
and attach it ...
header('Location: success.php?'.join('&', $my_query));
BUT ... that is now a GET string and will shown in the address bar. Does that matter?
If it does, you're back to doing like devinemke's way, or using sessions to store the variables across pages.
P.