我有这个问题
$total += $rows['price'] * $qty;
注意:未定义变量:第 42 行 D:\xampp\htdocs\WBPL-MusicLightDev\inc\functions.inc.php 中的总计
function wbpl_showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',', $cart);
//$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
echo '<form action="index.php?page=cart&action=update" method="post" id="cart">';
echo '<table border=0 align="center" class="table table-bordered">';
foreach ($contents as $id => $qty) {
$sql = "SELECT * from wbpl_product WHERE kd_product = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$rows=mysql_fetch_array($result);
//extract($row);
echo '<tr>
<td>Brand</td>
<td colspan="4">'. $rows['kd_product'] .'</td>
<tr>
<tr>
<td>Brand</td>
<td colspan="4">'. $rows['nama_brand'] .'</td>
<tr>
<tr>
<td>Instrument Type</td>
<td colspan="4">'. $rows['nama_instype'] .'</td>
</tr>
<tr">
<td rowspan="2">Price</td>
<td rowspan="2">Rp. ' . $rows['price'] . '</td>
<td rowspan="2"><input type="text" name="qty' . $id . '" value="' . $qty . '" size="2" maxlength="3" /></td>
<td rowspan="2">Rp. ' . ($rows['price'] * $qty) . '</td>
<td><a href="index.php?page=cart&action=delete&id=' . $id . '" class="btn btn-danger">Hapus</a></td>
</tr>
<tr><td><br></td></tr>';
$total += $rows['price'] * $qty;
}
echo '</table>';
$qty = getQty();
echo '<p>Sub Total: <strong> Rp. ' . $total . '</strong></p>';
//session_register('totalbayar');
$_SESSION['totalbayar'] = $total;
echo '<div><button type="submit" class="btn btn-primary">Update cart</button></div>';
echo '</form>';
} else {
echo '<p>Keranjang belanja masih kosong.</p>';
}
//return join('', $output);
}