2016-09-25 112 views
1

我无法比较set变量为null。我的代码运行作为通过if语句比较空数据

.......some code 
echo "Question1 is" . $q1. "is Question-1"; 
?> 

<html> 
<head> 
<form method="post" method="post" action="jobprocess.php"> 
<? 
    if($q1!="") 
    { ?> 
     <h3> Answer the below simple questions related to the job and apply </h3> 
     <div align="center"> 
     <input type="text" name="q1" required placeholder="<?php echo $q1;?>"><br> 
    <? } ..... some more code 

结果显示为

问题1 ISIS问题1

回答与工作有关的以下简单的问题,并应用

[文本框]

虽然第一行确认变量我无法理解为什么它进入!$ q1 =“”循环

感谢您的耐心等待 我已经经历了=== null和empty($ var)的用法,张贴了这个,我无法弄清楚什么是错我的代码

+0

更新:我曾尝试为0 SQL表中设置默认值和比较为0,仍它进入循环。我感觉到逻辑错误比语法错误 –

+0

http://php.net/manual/en/types.comparisons.php –

+0

'print_r($ q1)'的输出是什么;' –

回答

1

尝试使用if(!is_null($q1)),而不是你的条件的

+0

@ZigsawConsultancy我将它添加为答案 –