I made a loop then sum it into variable $jumlahtotal, what I confuse is the value in $jumlahtotal is true when I try to echo it, but I getting undefined variable error on this $jumlahtotal
Note : i tried declare it outside the foreach but still getting error undefined variable;
here's my code :
$total = 0;
$totalberat = 0;
if (isset($_SESSION['items'])) {
foreach ($_SESSION['items'] as $key => $val) {
$query = mysqli_query($koneksi, "select * from barang where br_id = '$key'");
$data = mysqli_fetch_array($query);
$jumlah_harga = $data['br_hrg']*$val;
$total += $jumlah_harga;
$berat = $data['brt_brg']*$val;
$totalberat += $berat;
$jumlahtotal += $val;
}}
?>