Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP IF Statement executing both conditions

I'm currently integrating a payment system into my website. I have a response script which basically takes in the data from the secure server and displays to the customer if the payment has gone through or not. My problem is that the if statement is actually displaying both messages to the customer, even if the payment has been 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:[email protected]"><b><u>[email protected]</u></b></a>

<?
}
?>

I have also tried doing this the following way, however with this method, the body is blank - no text is 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:[email protected]>[email protected]</a>";
echo $nothanks;
}
?>

And after that I tried to put the HTML into a seperate document and use require_once() but this didn't work either - same result as previous - blank body.

Any one have any ideas?

EDIT:

I have tried some of the ways suggested however I'm still having the blank page problem :(

Here is the way I have gone ->

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

This still gives me a blank page even though the syntax looks right?

like image 766
109221793 Avatar asked Nov 28 '22 12:11

109221793


2 Answers

Try:

if (($result == "00") && ($payersetup == "00") && ($pmtsetup =="00") ) {
   ...
   ...
}
like image 78
sdot257 Avatar answered Dec 05 '22 05:12

sdot257


To add to others answers:

Your original code:

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

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

PHP Parse error:  syntax error, unexpected T_BOOLEAN_AND

I think you've disabled your error reporting thats why you are seeing a blank page.

like image 32
codaddict Avatar answered Dec 05 '22 06:12

codaddict