Page 1 of 1

if statement return a new php page?

Posted: Thu Oct 23, 2008 1:16 pm
by ringartdesign
i have this if statement that returns a quote based on user input in an html form:

if (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="male"))
$quote=31.44;
elseif (($_POST['age'] >= 18) && ($_POST['age'] <= 25) && ($_POST['sex'] =="female"))
$quote=44.65;
elseif (($_POST['age'] >= 26) && ($_POST['age'] <= 30) && ($_POST['sex'] =="male"))
$quote=35.91;

is there a way to redirect someone to a different php page if they enter an age 65-80?

Thanks!

Re: if statement return a new php page?

Posted: Thu Oct 23, 2008 2:14 pm
by aceconcepts

Re: if statement return a new php page?

Posted: Thu Oct 23, 2008 5:08 pm
by oscardog

Code: Select all

 
header("location: WHERE_YOU_WANT_THEM_TO_GO.php");
 

Re: if statement return a new php page?

Posted: Thu Oct 23, 2008 11:30 pm
by novice4eva
The one and only problem with header is that it returns error in case you have anything echoed before it, even a space would. I like header if it didn't have that short come, so again there is javascript solution: but who knows who have their javascript disabled!! Hopefully if they are not, do something like this:

Code: Select all

 
elseif (($_POST['age'] >= 65) && ($_POST['age'] <= 80))
{
echo '<meta HTTP-EQUIV=\"refresh\" content=".$refreshTime.";url=\"".$url."\">';//WHERE $url is the page you want to redirect, $refreshTime is the time by which you delay the redirection, exactly what aceconcepts suggested
/* OR YOU COULD OPEN A NEW PAGE*/
echo '<script>window.open("'.$url.'");</script>';
/* OR YOU COULD OPEN IT IN THE SAME PAGE AS*/
echo '<script>window.location.href="'.$url.'";</script>';
}