我在购物车中收到邮件错误“警告:mysql_fetch_assoc():提供的参数不是有效的MySQL结果资源”并且我只在邮件上获得此文本“总计:$ 0.00”但购物车不是空的
function emailcartview() {
$total=0;
$totalvalue=0;
$str = '';
foreach($_SESSION as $name => $value) {
if ($value>0){
if (substr($name, 0, 5)=='cart_'){
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price, item_number FROM products WHERE id='.mysql_real_escape_string($id));
$cart = array();
while ($get_row = mysql_fetch_assoc($get)) {
$cart[] = array(
'hsid' => $get_row['id'],
'price' => $get_row['price'],
$price = $get_row['price'],
'itemno' => $get_row['item_number'],
'name' => $get_row['name'],
'value' => $value,
$sub = $value*$cost,
$total += $sub,
$totalvalue = $value,
'realsub' => number_format($sub, 2),
);
}
foreach($cart as $index => $record){
global $emailcart;
$str = "Item: {$record['itemno']} - {$record['name']} | Qty: {$record['value']} | Cost: {$record['price']} x {$record['value']} = {$record['realsub']} <br>";
}
}
}
}
$str = "Total : $".number_format($total, 2);
return $str;
}
答案 0 :(得分:0)
由于sql错误,可能mysql_query()
返回FALSE。由于脚本没有错误处理,因此这个FALSE已传递给mysql_fetch_assoc
。
$get = mysql_query('SELECT id, name, price, item_number FROM products WHERE id='.mysql_real_escape_string($id));
if ( !$get ) {
trigger_error(mysql_error(), E_USER_ERROR);
}