2013-05-03 57 views
-4

PHP代碼:PHP - 警告:mysqli_fetch_array()

<?php 

$name = $_GET['name']; 
$type = $_GET['type']; 
$desc = $_GET['desc']; 


     $con=mysqli_connect("localhost","root","","projdb"); 

     // Check connection 
     if (mysqli_connect_errno($con)) 
     { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
     } 

     $res = mysqli_query($con,"SELECT * FROM __scannedfiles WHERE description LIKE '%$desc%' AND title='$name' AND doctype='$type' "); 

     while($row = mysqli_fetch_array($res)){ 
      $path=$row[3]; 
      echo '<a target=\"_blank\" href="'.$path.'" title=\"\">'.$path.'</a> '; 
     } 
?> 

錯誤:

Warning: mysqli_error() expects exactly 1 parameter, 0 given. this is the error.

+0

請仔細閱讀本手冊,該函數在不同情況下可能返回的內容。然後閱讀如何獲取數據庫的錯誤消息。 – CBroe 2013-05-03 06:23:24

+0

複製粘貼不起作用? – shapeshifter 2013-05-03 06:23:54

+0

我猜__scannedfiles不存在,在任何情況下,運行查詢返回false。請檢查您的查詢。 – 2013-05-03 06:36:05

回答

0

這意味着您的查詢給錯誤,傳遞之前,將使用mysqli_error()在查詢查看錯誤

$res = mysqli_query($con,"SELECT * FROM __scannedfiles WHERE description LIKE '%$desc%' AND title='$name' AND doctype='$type' ") 
OR die(mysqli_error()); 
0

這意味着你的查詢失敗(因爲的語法錯誤或連接錯誤)。您應該驗證並把它傳遞着,像之前經歷:

if($res) { 
print "good job!"; 
}else { 
print "error"; 
} 
0

檢查$resmysqli_fetch_array。你會發現它是錯誤的,因爲查詢失敗。

if($res === FALSE) { 
die(mysql_error()); // TODO: better error handling 
} 

while($row = mysqli_fetch_array($res)){ 
     $path=$row[3]; 
     echo '<a target=\"_blank\" href="'.$path.'" title=\"\">'.$path.'</a> '; 
    } 

documentation

0

它告訴你,你的查詢有問題。查詢後執行以下操作:

echo mysqli_error($con); 

它會告訴你你的錯誤在哪裏。

0

這意味着您的查詢不會返回任何內容或者有任何不適用的內容。首先調試查詢

$res = mysqli_query($con,"SELECT * FROM __scannedfiles WHERE description LIKE '%$desc%' AND title='$name' AND doctype='$type' ") or die('Invalid query: ' . mysqli_error()); 

第二次檢查,如果該行存在

if (mysqli_num_rows($res) > 0) { 
    while($row = mysqli_fetch_array($res)){ 

Furhermore你是在sql injection風險,這裏有How can I prevent SQL injection in PHP?看看。您應該使用準備好的聲明以避免任何風險

+0

最新錯誤:警告:mysqli_error()期望恰好有1個參數,給出0。這是錯誤。 – user2335183 2013-05-03 06:35:43

+0

@ user2335183試試這個或者死(mysqli_error($ con)); – Fabio 2013-05-03 06:38:15

相關問題