fatmikey Posted November 3, 2008 Share Posted November 3, 2008 My code isn't doing what I want it to do. I want it to do a multipule if using a switch statement but it isn't working. It seems to ignore the default statement. Any ideas? if ($OnlinePayment == "Yes") { $Class =" "; } switch ($Class) { case "Group"; mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-group.htm\">"; break; case "Lunch Time Quickie"; mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-quickie.htm\">"; break; case "Private"; mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-private.htm\">"; break; case "Workshop"; mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-workshop.htm\">"; break; default: if (mail($To, $Subject, $Body, $Headers)) { print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.htm\">"; } else { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; break; } } Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/ Share on other sites More sharing options...
corbin Posted November 3, 2008 Share Posted November 3, 2008 So....... What exactly is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-680946 Share on other sites More sharing options...
fatmikey Posted November 3, 2008 Author Share Posted November 3, 2008 Basically how the code is supposed to work is like this: - the form asked if the person wants to pay online Yes or No. - the form asked the person to select a choice of classes to take In the PHP I am first trying to use an IF statement to say if they selected online payment then continue on to the switch statement and depending on the answer jump to another web page. At the end of that code I fake it out by zeroing out the class variable so it has no choice but to use the code at the end and allow the user to bypass the online payment section. Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-680948 Share on other sites More sharing options...
fatmikey Posted November 3, 2008 Author Share Posted November 3, 2008 I remove the first code because it didn't do anything. if ($OnlinePayment == "Yes") { $Class =" "; } How do I do a double check condition, meaning, first check to see if they selected online payment and if they did, then run through all the choices of the switch case and if they didn't select online payment just send an email? Thanks for your help . Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-680950 Share on other sites More sharing options...
kenrbnsn Posted November 3, 2008 Share Posted November 3, 2008 You've written your case statements wrong. You have <?php case "Group"; ?> it should be <?php case "Group": ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-680956 Share on other sites More sharing options...
fatmikey Posted November 3, 2008 Author Share Posted November 3, 2008 Thanks Ken, that helped. But now my conditional IF statement isn't working. I added an if before my switch statement and it seems to ignore my switch statement altogether, it just jumps past the switch statement. Thanks again for your help. Here is the altered code: if ($OnlinePayment) { switch ($Class) { case "Group": mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-group.htm\">"; break; case "Lunch Time Quickie": mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-quickie.htm\">"; break; case "Private": mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-private.htm\">"; break; case "Workshop": mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-workshop.htm\">"; break; } } if (mail($To, $Subject, $Body, $Headers)) { print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.htm\">"; } else { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-681131 Share on other sites More sharing options...
Andy-H Posted November 3, 2008 Share Posted November 3, 2008 if ($OnlinePayment) { switch ($Class) { case "Group": mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-group.htm\">"; $redirect = TRUE; break; case "Lunch Time Quickie": mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-quickie.htm\">"; $redirect = TRUE; break; case "Private": mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-private.htm\">"; $redirect = TRUE; break; case "Workshop": mail($To, $Subject, $Body, $Headers); print "<meta http-equiv=\"refresh\" content=\"0;URL=checkout-workshop.htm\">"; $redirect = TRUE; break; } } if (isset($redirect)) { print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.htm\">"; } else { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-681132 Share on other sites More sharing options...
fatmikey Posted November 3, 2008 Author Share Posted November 3, 2008 Hi, I'm not sure what that new code does, but I cut and pasted it and gave it a try and now it just displays an error condition and shows me my error page, error1.htm I'm thinking the problem is at the top with the IF statement, since the Yes/No doesn't seem to matter. Hope you can help. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-681144 Share on other sites More sharing options...
Andy-H Posted November 3, 2008 Share Posted November 3, 2008 If the code is re-directing you that means that $OnlinePayment must be set. The problem must be with the switch statement. Have you tried echoing $Class? Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-681155 Share on other sites More sharing options...
fatmikey Posted November 3, 2008 Author Share Posted November 3, 2008 Ok, I got it working now, I had to play around a bit by useing echo to display the onlinepayment. The problem was that the script wasn't passing the results to the PHP script. I forgot the POST command. It works now, thanks for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/#findComment-681209 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.