doujingao6210 2013-01-11 02:04
浏览 50
已采纳

PHP值条件错误测试

Is $var==1 the proper syntax for testing whether $var has a value?

I ask, because I'm getting a failure on a simple conditional.

Here's the code that seems to be failing:

if ($slcustom31==1) {$page="http://www.mydomain.com/members/page_Alpha.php";}

I assume that there's something wrong with the syntax, $var==1 .

++++++++ Here's the entire conditional, if that makes things clearer:

//condition 1
if ($slcustom31==1) {$page="http://www.mydomain.com/members/page_Alpha.php";} 

//condition2
elseif ($slcustom31!=1 AND $slcustom29!="") {$page="http://www.mydomain.com/members/".$slcustom29;}

//condition3
else {$page="http://www.mydomain.com/members/page_Beta.php";} 

sl_redirecttourl($page);

SPECIFIC SYMPTOM: Script ignores condition1 and condition2, defaults to condition3.

++++ And if it helps, here's the entire (short) script:

$groupswithaccess="somegroup";

require_once("../slpw/sitelokpw.php");
require_once("../slpw/sitelokapi.php"); //gets value being tested by conditional

if ($slcustom31==1) {$page="http://www.mydomain.com/members/page_Alpha.php";} 
elseif ($slcustom31!=1 AND $slcustom29!="") {$page="http://www.mydomain.com/members/".$slcustom29;}//not finished, but started
else {$page="http://www.mydomain.com/members/page_Beta.php";} 

sl_redirecttourl($page);

Can someone tell me what I should do differently?

Thanks!

  • 写回答

3条回答 默认 最新

  • dongwei4652 2013-01-11 02:08
    关注
    if($var ==1){
    //returns true only if var is 1
    }
    
    if(isset($var)){
    //returns true if you currently have any value stored as the variable $var
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?