So I took CroNiX's advice and put this php redirect function at top of the page.
<?php
function redirect_to($new_location){
header("Location: " . $new_location);
exit;
}
$page_ok=$_POST['firstName'];
if($page_ok=="userFirstName"){
redirect_to("http://www.google.com");
}else{
redirect_to("http://www.msn.com");
}
?>
My page is designed to post to itself but after saving the data to the database, assuming it passes validation, I want to send the user to another page. With the php code at the top of the page, as soon as I type the page in the browser's address field it redirects to the second url: redirect_to("http://www.msn.com");
How can I make the function fire only after the button click?