AnotherQuestion Posted September 13, 2009 Share Posted September 13, 2009 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 https://forums.phpfreaks.com/topic/174119-if-then-else/ Share on other sites More sharing options...
phporcaffeine Posted September 13, 2009 Share Posted September 13, 2009 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 https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-917812 Share on other sites More sharing options...
AnotherQuestion Posted September 13, 2009 Author Share Posted September 13, 2009 I have changed the = to == and it still fails to work. Link to comment https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-917825 Share on other sites More sharing options...
phporcaffeine Posted September 13, 2009 Share Posted September 13, 2009 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 https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-917827 Share on other sites More sharing options...
AnotherQuestion Posted September 13, 2009 Author Share Posted September 13, 2009 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 https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-917832 Share on other sites More sharing options...
cbolson Posted September 13, 2009 Share Posted September 13, 2009 Hi, can you print out the session vars as they are right before you decide which page to show? Clearly the $_SESSION["Normal"] is not being changed to "False" Chris Link to comment https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-917839 Share on other sites More sharing options...
AnotherQuestion Posted September 13, 2009 Author Share Posted September 13, 2009 LargeEngine:TRUE Special:TRUE 4x4:FALSE Normal:FALSE Link to comment https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-917843 Share on other sites More sharing options...
cbolson Posted September 13, 2009 Share Posted September 13, 2009 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 https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-917845 Share on other sites More sharing options...
phporcaffeine Posted September 13, 2009 Share Posted September 13, 2009 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 https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-917846 Share on other sites More sharing options...
AnotherQuestion Posted September 19, 2009 Author Share Posted September 19, 2009 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 https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-921253 Share on other sites More sharing options...
knsito Posted September 19, 2009 Share Posted September 19, 2009 You fixed the =, == problem but you introduced problems with your array associations. Try without the '$' in your arrays ie: $_SESSION['$MakeSpecial'] should be $_SESSION['MakeSpecial'] etc Link to comment https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-921262 Share on other sites More sharing options...
AnotherQuestion Posted September 21, 2009 Author Share Posted September 21, 2009 I have removed the $and still no joy. it always goes to ElseIf ($_SESSION['Special'] == TRUE) { $URL="http://www./Quote/GoldQuoteResult1.php"; header ("Location: $URL"); } Link to comment https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-922595 Share on other sites More sharing options...
AnotherQuestion Posted September 22, 2009 Author Share Posted September 22, 2009 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 https://forums.phpfreaks.com/topic/174119-if-then-else/#findComment-923116 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.