开发者

PHP echo if post equals, help

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜