2016-09-25 181 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我將它添加爲答案 –