Sounds like all you need to do is invert the order of the code you have written.
if($_POST['submit']){
// process input
// then redirect
header($success_url);
} else {
// output the HTML form
}
... instead of
<various html at top>
<?
if($_POST['submit']){ // et cetera