因此,在网上商店写下我的第一个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现在你说出来了! :)(尼尔,有关错误检查的建议仍然成立) –