PHP - 如果不能正常工作

时间:2014-05-21 00:15:46

标签: php if-statement

我尝试切换语句但仍然相同...现在我选择的所有选项都在$cimb ...任何人都可以帮助我让他们重定向到正确的网址吗?

以下是我的编码:

$detectpay = mysql_query("select paymethod from themetransaction");
                $showdpay = mysql_fetch_array($detectpay);
                $credit = "Credit Card";
                $cimb = "CIMB Clicks";
                $may = "Maybank2U";
                $paypal = "Paypal";
                $public = "Public eBank";
                $rhb = "RHB Now";
                switch($showdpay['paymethod'])
                    {
                        case $credit:
                            $echo = "<meta http-equiv='refresh' content='5;url=http://www.facebook.com/' />";
                            break;
                        case $cimb:
                            $echo = "<meta http-equiv='refresh' content='5;url=https://www.cimbclicks.com.my/ibk/' />";
                            break;
                        case $may:  
                            $echo =  "<meta http-equiv='refresh' content='5;url=https://www.maybank2u.com.my/mbb/m2u/common/M2ULogin.do?action=Login' />";
                            break;
                        case $paypal:   
                            $echo =  "<meta http-equiv='refresh' content='5;url=https://www.paypal.com/my/cgi-bin/webscr?cmd=_login-submit' />";
                            break;
                        case $public:
                            $echo =  "<meta http-equiv='refresh' content='5;url=https://www2.pbebank.com/myIBK/apppbb/servlet/BxxxServlet?RDOName=BxxxAuth&MethodName=login' />";
                            break;
                        case $rhb:
                            $echo =  "<meta http-equiv='refresh' content='5;url=https://logon.rhb.com.my/ />";
                            break;
                        default:
                            $echo = "none of the above worked...";
                    }


                echo $echo; 

3 个答案:

答案 0 :(得分:3)

您的if需要双等号:==

if($showdpay['paymethod'] == $credit) //and so on...

但是看到你的代码,我应该建议使用switch语句。

一点帮助:

您可以从中重写代码:

if($showdpay['paymethod'] == $credit)
{
    echo " <meta http-equiv='refresh' content='5;url=http://www.facebook.com/' />";
}
elseif($showdpay['paymethod'] == $cimb)
{
    echo"<meta http-equiv='refresh' content='5;url=https://www.cimbclicks.com.my/ibk/' />";
}

到此:

switch($showdpay['paymethod'])
{
    case $credit:
        $echo = "<meta http-equiv='refresh' content='5;url=http://www.facebook.com/' />";
        break;
    case $cimb:
        $echo = "<meta http-equiv='refresh' content='5;url=https://www.cimbclicks.com.my/ibk/' />";
        break;
    default:
        $echo = "none of the above worked...";
}

echo $echo;

答案 1 :(得分:0)

您赞成使用=使用==来比较值

if($showdpay['paymethod'] == $credit)

答案 2 :(得分:0)

使用==进行比较。单=用于在变量中分配值。

 if($showdpay['paymethod'] = $credit)

应该是:

 if($showdpay['paymethod'] == $credit)

同时更改所有if else块。

if($showdpay['paymethod'] = $credit)在执行$credit to $showdpay['paymethod']之前分配if,因此PHP现在将其视为if("Credit Card");,它将一如既往地返回true。

编辑以查询您的信息。

$detectpay = mysql_query("select paymethod from themetransaction");

应该是:

$detectpay = mysql_query("select paymethod from themetransaction where paymethod = '".$var."'");

其中$var是您在选择框中选择的那个。如果信用卡是themetransaction表中的第一条记录,您的代码将始终获得信用卡。