title: Undefined variable: total
body: <p>I'm having problems with this</p>
  
  <pre><code>$total += $rows['price'] * $qty;
  </code></pre>
  
  <p>Notice: Undefined variable: total in D:\xampp\htdocs\WBPL-MusicLightDev\inc\functions.inc.php on line 42</p>
  
  <pre><code>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 '&lt;form action="index.php?page=cart&amp;action=update" method="post" id="cart"&gt;';
          echo '&lt;table border=0 align="center" class="table table-bordered"&gt;';
  
  
          foreach ($contents as $id =&gt; $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    '&lt;tr&gt;
                          &lt;td&gt;Brand&lt;/td&gt;
                          &lt;td colspan="4"&gt;'. $rows['kd_product'] .'&lt;/td&gt;
                      &lt;tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;Brand&lt;/td&gt;
                          &lt;td colspan="4"&gt;'. $rows['nama_brand'] .'&lt;/td&gt;
                      &lt;tr&gt;
                      &lt;tr&gt;
                              &lt;td&gt;Instrument Type&lt;/td&gt;
                              &lt;td colspan="4"&gt;'. $rows['nama_instype'] .'&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr"&gt;
                      &lt;td rowspan="2"&gt;Price&lt;/td&gt;
                      &lt;td rowspan="2"&gt;Rp. ' . $rows['price'] . '&lt;/td&gt;
                      &lt;td rowspan="2"&gt;&lt;input type="text" name="qty' . $id . '" value="' . $qty . '" size="2" maxlength="3" /&gt;&lt;/td&gt;
  
                      &lt;td rowspan="2"&gt;Rp. ' . ($rows['price'] * $qty) . '&lt;/td&gt;
  
                      &lt;td&gt;&lt;a href="index.php?page=cart&amp;action=delete&amp;id=' . $id . '" class="btn btn-danger"&gt;Hapus&lt;/a&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;&lt;td&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;';
              $total += $rows['price'] * $qty;
          }
          echo '&lt;/table&gt;';
          $qty = getQty();
  
  
          echo '&lt;p&gt;Sub Total: &lt;strong&gt; Rp. ' . $total . '&lt;/strong&gt;&lt;/p&gt;';
  
  
  
          //session_register('totalbayar');
          $_SESSION['totalbayar'] = $total;
          echo '&lt;div&gt;&lt;button type="submit" class="btn btn-primary"&gt;Update cart&lt;/button&gt;&lt;/div&gt;';
          echo '&lt;/form&gt;';
      } else {
          echo '&lt;p&gt;Keranjang belanja masih kosong.&lt;/p&gt;';
      }
      //return join('', $output);
  }
  </code></pre>