PHP IF Statement fulfilling both conditions

I am currently integrating a payment system into my website. I have a script response that basically takes data from a secure server and displays it to the client if the payment passed or not. My problem is that the if statement actually displays both messages to the client, even if the payment was successful or unsuccessful.

Here is the If statement:

<? if ($result == "00") && ($payersetup == "00") && ($pmtsetup =="00"){ ?> Thank you <br/><br/> To return to the home page <a href="http://www.xx.com"><b><u>click here</u></b></a> <br/><br/> <? } else { ?> <br/><br/> There was an error processing your subscription. To try again please <a href="http://www.xx.com/signUp.html"><b><u>click here</u></b></a><br><BR> Please contact our customer care department at <a href="mailto: support@xx.com "><b><u> support@xx.com </u></b></a> <? } ?> 

I also tried to do it as follows, but with this method the body is empty - the text is not displayed.

 <? if ($result == "00") && ($payersetup == "00") && ($pmtsetup =="00"){ $thanks = "Thank you! \n\n To Return to the homepage <a href=http://www.epubdirect.com>Click Here</a>"; echo $thanks; } else { $nothanks = "There was an error processing your subscription.\n\n To try again please <a href=http://www.epubdirect.com/signUp.html>click here</a>. \n\n If the problem persists, please contact our customer care department at <a href=mailto: support@epubdirect.com > support@epubdirect.com </a>"; echo $nothanks; } ?> 

And after that I tried to put the HTML in a separate document and use require_once (), but that didn’t work either - the same as the previous one - an empty body.

Does anyone have any ideas?

EDIT:

I tried some of the suggested methods, but I still have a problem with a blank page :(

That's how I left →

 <? if (($result == "00") && ($payersetup == "00") && ($pmtsetup =="00")) { require_once('thankyou.html'); } else { require_once('error.html'); } ?> 

Does this still give me a clean page, although the syntax looks right?

+4
source share
7 answers

Try:

 if (($result == "00") && ($payersetup == "00") && ($pmtsetup =="00") ) { ... ... } 
+10
source

To add to other answers:

Source:

 if ($result == "00") && ($payersetup == "00") && ($pmtsetup =="00") 

is a syntax error. After the PHP parser sees ) , which marks the end of the if conditional, it expects to see another statement or { to mark the beginning of the if body. But when he sees && , he throws this syntax error:

 PHP Parse error: syntax error, unexpected T_BOOLEAN_AND 

I think you turned off the error report, so you see a blank page.

+9
source

I wonder how your condition is triggered at all, because you have ( and ) in your if conditions:

 if (($result == "00") && ($payersetup == "00") && ($pmtsetup =="00")){...} 

Or simply:

 if ($result == "00" && $payersetup == "00" && $pmtsetup =="00"){...} 
+3
source

You probably mean:

 if ($result == "00" && $payersetup == "00" && $pmtsetup == "00") { 

if ends after closing ) .

+2
source

Simple clean way

 <? if (($result == "00") && ($payersetup == "00") && ($pmtsetup =="00")):?> Thank you <br/><br/> To return to the home page <a href="http://www.xx.com"><b><u>click here</u></b></a> <br/><br/> <?php else : ?> <br/><br/> There was an error processing your subscription. To try again please <a href="http://www.xx.com/signUp.html"><b><u>click here</u></b></a><br><BR> Please contact our customer care department at <a href="mailto: support@xx.com "><b><u> support@xx.com </u></b></a> <?php endif ?> 
+2
source

Here's what you need to do to enable error reporting:

In your PHP script: use the error_reporting function described here .

Or, if you have access to your php.ini, refer to this document .

You must use a local development server (for example, XAMPP on Windows / Linux ) on your own computer, and when you are done deploying to a real server.

+2
source

As others pointed out, you need to enclose several conditions in an if statement in parentheses:

  if (($ cond1) && ($ cond2)) {...} 

Failure to do so will result in a fatal analysis error.

HOWEVER, if this was the main cause of the problem, the execution of this page would stop at this line and display a PHP error for the browser or a blank page. The original message states that this is not what is happening; instead, both HTML blocks are output.

Have you looked at the source in your browser to see if there is anything sent to the browser? I half suspect that you are using short open tags (given because you are using them in a block of code) and your PHP configuration is set to disabled. This will cause the entire block of code to be sent as is to the browser, which means that the fatal parsing error never starts, and the browser considers the <? ... ?> <? ... ?> as invalid HTML and simply ignores it. This causes both blocks of HTML to render as described.

Of course, if short open tags are included, I have no idea. :-)

+1
source

All Articles