因此,在網上商店寫下我的第一個PHP網站。我已經寫了一段代碼,用於選擇產品數據庫和類別的所有產品,然後使用相同的product_id
選擇前面的圖片顯示圖像。PHP錯誤:「提供的參數不是有效的MySQL結果資源」
代碼如下:
<?PHP
include_once "db.php";
$result = "(select * FROM products WHERE product_type = 'weddingdressaline') inner join (select * FROM images WHERE postion = 'front') images on products.product_id = images.product_id";
while($row = mysql_fetch_array($result)) {
$content = $row['image'];
header('Content-type: image/jpg');
echo $content;
echo $row['price'];
}
mysql_free_result($result);
mysql_close();
?>
但是當我運行該腳本,我得到了以下錯誤:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in **/weddingdressaline.php on line 4
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in **/weddingdressaline.php on line 11
現在,我敢肯定,對於第二個錯誤的原因是因爲發生第一個錯誤。任何幫助你可以給我會非常感激。
歡迎堆棧溢出!你沒有做任何錯誤檢查。你需要*在mysql_query()調用後執行該操作,如果發生錯誤,使用'mysql_error()'輸出錯誤。否則,如果查詢失敗,腳本就會中斷。如何做到這一點在[mysql_query()'](http://php.net/mysql_query)手冊或本[參考問題。](http://stackoverflow.com/questions/6198104/reference -what-a-perfect-code-sample-using-the-mysql-extension) –
@Pekka:你看到一個'mysql_query'調用嗎? ;) – Ryan
@mini現在你說出來了! :)(尼爾,有關錯誤檢查的建議仍然成立) –