开发者

PHP echo if post equals, help

开发者 https://www.devze.com 2022-12-31 05:06 出处:网络
I am trying to echo the action for my form if a post equals \'paypal\' This is what I have: <?php if $_POST[\'method\'] == \'paypal\' echo \'action=\"paypal/process.php\"\' else ech开发者_JAVA技巧

I am trying to echo the action for my form if a post equals 'paypal'

This is what I have:

<?php if $_POST['method'] == 'paypal' echo 'action="paypal/process.php"' else ech开发者_JAVA技巧o 'action="moneybookers/process.php" '?> 

Do i need to print the variable before I do this? what am I doing wrong?

I get this error:

Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in /var/www/account/credits/credit_amount.php on line 27


You are missing parentheses around your if conditional statement:

<?php if( $_POST['method'] == 'paypal' ) 
           echo 'action="paypal/process.php"';
      else 
           echo 'action="moneybookers/process.php"';
?>


You should try to format your code properly (ex. parentheses in if statement):

<?php
if ($_POST['method'] == 'paypal') {
    echo 'action="paypal/process.php"';
} else {
    echo 'action="moneybookers/process.php"';
}
?> 


It looks as though you formatted it that way because you are displaying the results of that code in a template. You could cut down on the amount of code you need by using a ternary operator:

action="<?php echo ($_POST['method'] == 'paypal' ? 'paypal' : 'moneybookers'); ?>/process.php"

It's essentially the same as saying if condition is true then return A otherwise return B

0

精彩评论

暂无评论...
验证码 换一张
取 消