Jump to content

Recommended Posts

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;
}
}

Link to comment
https://forums.phpfreaks.com/topic/131150-solved-double-if-statement-help-please/
Share on other sites

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.

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 .

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\">";

}

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\">";

}

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.

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.

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.