2016-01-18 38 views
0

我有一個JavaScript日曆SQL查詢禁用日曆

<input type="text" size="8" id="date" name="calendar[]" /> 

當我輸入下面的PHP它禁用日曆。

$result=mysql_query("select * from products where id='maui'"); 
while($row=mysql_fetch_array($result)){ 

但如果我輸入沒有PHP的「where子句」它的工作原理:

$result=mysql_query("select * from products"); 
while($row=mysql_fetch_array($result)){ 

什麼是一個變通的一些選項?

回答

1

我會想象在你的查詢中有一個語法錯誤,或者id不存在,因此沒有返回結果。因此,經常檢查數據庫訪問調用

$result=mysql_query("select * from products where id='maui'"); 
if ($result === FALSE) { 
    echo mysql_error(); 
    exit; 
} 
if (mysql_num_rows() == 0) { 
    echo 'No results returned'; 
    exit; 
} 
while($row=mysql_fetch_array($result)){ 

請不要使用mysql_數據庫擴展,它已被棄用(在PHP7一去不復返)的狀態 特別是如果你剛開始學習PHP,花你的精力學習PDOmysqli_數據庫擴展, and here is some help to decide which to use