4

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?

2
  • 2
    If you're getting a blank page, it's probably throwing syntax errors but not displaying them. Try turning error reporting on in your php.ini (or else check your server logs for PHP errors). Commented Sep 22, 2010 at 13:21
  • Configure your error reporting to show you errors and warnings: php.net/manual/en/function.error-reporting.php Commented Sep 22, 2010 at 13:37

7 Answers 7

10

Try:

if (($result == "00") && ($payersetup == "00") && ($pmtsetup =="00") ) {
   ...
   ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I think the missing parentheses are the problem.
9

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.

3 Comments

Moral of the story: Turn on all error reporting during development.
@Andrew - how to I turn on error reporting? I am working on a server I did not set up.
@TaraWalsh You can set error reporting in the script using the error_reporting() function: php.net/manual/en/function.error-reporting.php
3

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

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

Or simply:

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

Comments

2

You probably mean:

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

The if ends after the closing ).

Comments

2

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:[email protected]"><b><u>[email protected]</u></b></a>
<?php endif ?>

2 Comments

I'd voted it down (hastily, which I undid) because it's a bad answer. All you did was rewrite the original code in your own style with no justification of why it's better and no explanation of what was wrong in the first place. How is anybody supposed to learn from this?
thanks for highliting , Problem is with if as every one knows out of it. if you see all answers in this post , you will find i am using if(): which gives a clean way to embed in html. this is alternative of all other answer.
2

Here is what you have to do to turn error reporting on:

In your PHP-script: Use the function error_reporting, described here.

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

You should use a local development server (like XAMPP on Windows/Linux) on your own computer and when you are done deploy on the real server.

Comments

1

As others have pointed out, you need to wrap multiple conditions in your if statement in parentheses:

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

Failure to do so will cause a fatal parse error.

HOWEVER, if this was the root cause of the problem, execution of the page would stop on that line, and render either a PHP error to the browser or a blank page. The original post indicates that this isn't what happens; instead, both HTML blocks are output.

Have you viewed the source in your browser to see if there is anything sent to the browser? I half suspect that you're using short open tags (given, since you use them in the code block), and your PHP config is set to disallow them. This would cause the entire code block to be sent as-is to the browser, which means that the fatal parse error is never triggered, and the browser treats the <? ... ?> block as invalid HTML and simply ignores it. This causes both HTML blocks to render as described.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.