Jump to content

If Then Else


AnotherQuestion

Recommended Posts

I have a script which is supposed to take user to different pages depending on their input on a previous form. I have checked that the correcr values are getting to this code.

 

$_SESSION['Normal']= "TRUE";
$_SESSION['RegNo'] = $_GET['RegNo'];
$_SESSION['Make'] = $_GET['Make'];
$_SESSION['Model'] =$_GET['Model'];
$_SESSION['EngineSize'] =$_GET['EngineSize'];
If ($_GET['4wdYes'] = 'on') 
{
$_SESSION['FourWheelDrive'] = "TRUE" ;
$_SESSION['Normal']= "FALSE";
}
If ($_GET['4wdNo'] = 'on') 
{
$_SESSION['FourWheelDrive'] = "FALSE" ;
$_SESSION['Normal']= "FALSE";
}
If ($_SESSION['EngineSize'] >= '3000')
{
$_SESSION['LargeEngine'] ="TRUE";
$_SESSION['Normal']= "FALSE";
}										
If ($_SESSION['Make'] == 'BMW'){$_SESSION['MakeCheck'] = "TRUE";}
If ($_SESSION['Make'] == 'MERCEDES') {$_SESSION['MakeCheck'] = "TRUE";}																						
If ( ($_SESSION['MakeCheck'] =="TRUE") AND 
     ($_SESSION['EngineSize'] >='2000') ) 
{
    $_SESSION['Special'] = "TRUE";
$_SESSION['Normal']= "FALSE";
}

If ($_SESSION['Normal'] = "TRUE")
{
$URL="http://www.ultimatblablay.com/Quotes/GoldQuote2.php";
header ("Location: $URL");
}

ElseIf ($_SESSION['Special'] = "TRUE")
{
$URL="http://www.ultimateblablanty.com/Quotes/GoldQuote3.php";
header ("Location: $URL");
}

ElseIf ($_SESSION['LargeEngine'] = "TRUE")
{
$URL="http://www.ultimatevehiclanty.com/Quotes/GoldQuote4.php";
header ("Location: $URL");
}

Else {
$URL="http://www.ultimablaba.com/Quotes/GoldQuote5.php";
header ("Location: $URL");
}
?>

However it always sends users to the same place

 

goldquote2. The first line

 

Link to comment
Share on other sites

When evaluating an 'equal to' condition you must use the ' == ' or ' <> ' operators.  Using a single ' = ' will not work and the conditional argument will not produce the expected result.

 

If ($_GET['4wdYes'] = 'on') SHOULD BE If ($_GET['4wdYes'] == 'on')

 

If ($_GET['4wdNo'] = 'on') SHOULD BE If ($_GET['4wdNo'] == 'on')

Link to comment
Share on other sites

Put:

var_dump($_GET);

as the first line in the code that you put here and then submit your form like normal with the values that you think should be giving you a different result than you are getting.  The whole $_GET stack will dump and then we can see what is actually being presented to the code.  Please post the dump results.

Link to comment
Share on other sites

Did a test with form.

 

array(6) { ["RegNo"]=> string(7) "Ck57HZZ" ["Make"]=> string(3) "BMW" ["Model"]=> string(4) "318i" ["EngineSize"]=> string(4) "3000" ["4wdNo"]=> string(2) "on" ["Next"]=> string(4) "Next" }

 

 

with these results it should set $Session['Special'] ="True"

 

and goto goldquote3.php

 

 

instead it goes to line 37 --> goldquote2.php

 

Link to comment
Share on other sites

well I'm baffled.

 

Assuming that you have changed all the appropriate = to == as phpORcaffine mentioned this really should work.

Unless...

As I am sure you know, "true" is normally used for Boolean values.

Hoever, for whatever reason, here you are using them as a normal string, but maybe in your IF clause php  interprets $_SESSION["Normal"] as being true (boolean) because it is defined and has a value....

 

Doesn't sound right but might be worth testing with a differnt value other than the words "TRUE" and "FALSE"

 

Chris

Link to comment
Share on other sites

Did you also change:

If ($_SESSION['Normal'] = "TRUE")
{
$URL="http://www.ultimatblablay.com/Quotes/GoldQuote2.php";
header ("Location: $URL");
}

TO

If ($_SESSION['Normal'] == "TRUE")
{
$URL="http://www.ultimatblablay.com/Quotes/GoldQuote2.php";
header ("Location: $URL");
}

 

Notice the '==' and not the '='. You may take a moment and ensure that all 'equal to' conditions are using the '==' operator and not a single '='.

Link to comment
Share on other sites

I have changed the code and it still doesnt't work.

 

unset($_SESSION['Normal']);
unset($_SESSION['LargeEngine']);
unset($_SESSION['EngineLarge']);
unset($_SESSION['EngineSpecial']);
unset($_SESSION['MakeSpecial']);
unset($_SESSION['Special']);

If ($_SESSION['EngineSize'] >=2000) {$_SESSION['EngineSpecial'] = TRUE;}
If ($_SESSION['Make'] == 'BMW') {$_SESSION['$MakeSpecial'] = TRUE;}
If ($_SESSION['Make'] == 'MERCEDES') {$_SESSION['$MakeSpecial'] = TRUE;}

If ($_SESSION['EngineSize'] >=3000) 
{$_SESSION['EngineLarge'] = TRUE;
 $_SESSION['Normal'] = FALSE;	
}

If (($_SESSION['$MakeSpecial'] == TRUE) AND
 ($_SESSION['$EngineSpecial'] == TRUE)) 
{ $_SESSION['Special'] = TRUE;
  $_SESSION['Normal'] = FALSE;
}

If ($_SESSION['FourWheelDrive'] = "Yes")
{$_SESSION['Normal'] = FALSE;
}

If ($_SESSION['Normal'] == TRUE)
{
$URL="http://www.ultom/Quote/GoldQuoteResult.php";
header ("Location: $URL"); 
}

ElseIf ($_SESSION['Special'] == TRUE)
{
$URL="http://www./Quote/GoldQuoteResult1.php";
header ("Location: $URL");
}

ElseIf ($_SESSION['FourWheelDrive'] == "Yes")
{
$URL="http://www.ult/Quote/GoldQuoteResult2.php";
header ("Location: $URL");
}

ElseIf ($_SESSION['LargeEngine'] == TRUE)
{
$URL="http://www.ulti/Quote/GoldQuoteResult3.php";
header ("Location: $URL");
}

Link to comment
Share on other sites

I thought id try placing the TRUE & FALSE into 'TRUE' and 'FALSE'

 

still dosent work

 

unset($_SESSION['Normal']);
unset($_SESSION['LargeEngine']);
unset($_SESSION['EngineLarge']);
unset($_SESSION['EngineSpecial']);
unset($_SESSION['MakeSpecial']);
unset($_SESSION['Special']);
$_SESSION['Normal'] = 'TRUE';

If ($_SESSION['EngineSize'] >=2000) {$_SESSION['EngineSpecial'] = 'TRUE';}
If ($_SESSION['Make'] == 'BMW') {$_SESSION['MakeSpecial'] = 'TRUE';}
If ($_SESSION['Make'] == 'MERCEDES') {$_SESSION['MakeSpecial'] = 'TRUE';}

If ($_SESSION['EngineSize'] >=3000) 
{$_SESSION['EngineLarge'] = 'TRUE';
 $_SESSION['Normal'] = 'FALSE';	
}

If (($_SESSION['$MakeSpecial'] == 'TRUE') AND
 ($_SESSION['$EngineSpecial'] == 'TRUE')) 
{ $_SESSION['Special'] = 'TRUE';
  $_SESSION['Normal'] = 'FALSE';
}

If ($_SESSION['FourWheelDrive'] = "Yes")
{$_SESSION['Normal'] = 'FALSE';
}

If ($_SESSION['Normal'] == 'TRUE')
{
$URL="http://www.u.com/Quote/GiltQuoteResult1.php";
header ("Location: $URL"); 
}

ElseIf ($_SESSION['Special'] == 'TRUE')
{
$URL="http://www.nty.com/Quote/GiltQuoteResult2.php";
header ("Location: $URL");
}

ElseIf ($_SESSION['FourWheelDrive'] == "Yes")
{
$URL="http://www..com/Quote/GiltQuoteResult3.php";
header ("Location: $URL");
}

ElseIf ($_SESSION['LargeEngine'] == 'TRUE')
{
$URL="http://www.u.com/Quote/GiltQuoteResult4.php";
header ("Location: $URL");
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.