2014-04-18 37 views
-1

我已经在opencart中创建了一个webstore。我为卖家添加了一些额外的页面来注册和销售他们的产品。当卖家添加产品时,它返回:警告:mysql_fetch_assoc()期望参数1是资源,布尔在第45行给出的/home/content/30/10933330/html/sales/save_item.php

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/content/30/10933330/html/sales/save_item.php on line 45 

并且产品未添加到主页面。

我的代码是:

mysql_query("insert into oc_product (model,seller_id,quantity,price,image,status,listing_days) values ('$model','".$_SESSION['seller_id']."','$qnt','$price','data/no_image.jpg','1','$datetime')"); 
mysql_query("insert into seller_balance (seller_id,amount,remark) values('".$_SESSION['seller_id']."','$amount','$remark')"); 
$product_id=mysql_query("select product_id from oc_product where seller_id='".$_SESSION['seller_id']."' order by product_id desc"); 
$product_fetch=mysql_fetch_assoc($product_id); 
$product_id_result=$product_fetch['product_id']; 
mysql_query("insert into oc_product_description (product_id,language_id,name,description) values ('$product_id_result','1','$name','$description')"); 
mysql_query("insert into oc_product_to_category (product_id,category_id) values('$product_id_result','$category')"); 
mysql_query("insert into oc_product_to_store (product_id,store_id) values('$product_id_result','0')"); 
echo' 
    <div id="div_after_save" style="float:left;"> 
<br/> 
<br/> 
<small><strong style="color:#000; font-size:12px;">Upload Image<br/> 
<form action="send_hp.php" id="hp_form" method="POST" enctype="multipart/form-data"> 
    <input type="file" name="h_pic" id="hp_upload" style="color:#000;" required="required" /> 
    <input type="hidden" name="product_id" id="product_id" value="'.$product_id_result.'"/> 
    </form></strong></small>'; 

echo'<div id="image_div" style="width:300px; height:150px;"> 
</div>'; 

} 
?> 

请帮助

+0

哪一行是“第45行”? – Helpful

回答

0

首先检查你的查询是正确

正确的方式做,这是

$query = mysql_query('Select * from table_name'); 

if($query) { 
while ($row = mysql_fetch_assoc($query) { 

    } 

} else { 
    throw new My_Db_Exception('Database error: ' . mysql_error()); 
} 
0

一个更好的想法,是使用mysql_insert_id() 也可能想要查看使用预处理语句nd MySQLI for OpenCart,存在指南,但超出了问题范围。

mysql_query("insert into oc_product (model,seller_id,quantity,price,image,status,listing_days) values ('$model','".$_SESSION['seller_id']."','$qnt','$price','data/no_image.jpg','1','$datetime')"); 
$product_id_result = mysql_insert_id(); 
    mysql_query("insert into seller_balance (seller_id,amount,remark) values('".$_SESSION['seller_id']."','$amount','$remark')"); 

    mysql_query("insert into oc_product_description (product_id,language_id,name,description) values ('$product_id_result','1','$name','$description')"); 
    mysql_query("insert into oc_product_to_category (product_id,category_id) values('$product_id_result','$category')"); 
    mysql_query("insert into oc_product_to_store (product_id,store_id) values('$product_id_result','0')"); 
    echo' 
     <div id="div_after_save" style="float:left;"> 
    <br/> 
    <br/> 
    <small><strong style="color:#000; font-size:12px;">Upload Image<br/> 
    <form action="send_hp.php" id="hp_form" method="POST" enctype="multipart/form-data"> 
     <input type="file" name="h_pic" id="hp_upload" style="color:#000;" required="required" /> 
     <input type="hidden" name="product_id" id="product_id" value="'.$product_id_result.'"/> 
     </form></strong></small>'; 

    echo'<div id="image_div" style="width:300px; height:150px;"> 
    </div>'; 

    } 
    ?> 
相关问题