title: My Cart Div is not refreshing until i press refresh symbol
body: <p>I am starting a cart session on my cart page but cart dropdown is not updating with a count until I refresh the page. I just want to update the div without reloading.</p>
  
  <p>I am using <code>foreach</code> but it doesn't work. What should I do now.</p>
  
  <pre><code>&lt;?php
  session_start();
  require_once("product.php");
  ?&gt;
                          &lt;li class="header-cart dropdown default-dropdown"&gt;
                              &lt;a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true"&gt;
                                  &lt;div class="header-btns-icon"&gt;
                                      &lt;i class="fa fa-shopping-cart"&gt;&lt;/i&gt;
                                  &lt;?php 
  if(isset($_SESSION['cart'])){
  
  
  ?&gt;      
                                      &lt;span class="qty"&gt;&lt;?php echo count($_SESSION['cart'])?&gt;&lt;/span&gt;
  
  
                                      &lt;?php
  }else{
                                      ?&gt;
                                      &lt;span class="qty"&gt;0&lt;/span&gt;
  
              &lt;?php
  
  }
              ?&gt;
                                  &lt;/div&gt;
                                  &lt;strong class="text-uppercase"&gt;My Cart:&lt;/strong&gt;
                                  &lt;br&gt;
                              &lt;span&gt;Shop Now&lt;/span&gt;
                              &lt;/a&gt;
                              &lt;div class="custom-menu"&gt;
                                  &lt;div id="shopping-cart"&gt;
                                      &lt;div class="shopping-cart-list"&gt;
                                      &lt;?php
  
        @$cart = unserialize(serialize($_SESSION['cart']));
        $total = 0;
        if($cart){
        foreach($cart as $k=&gt;$v)
          {
  
  
          $total += $v-&gt;price * $v-&gt;quantity;
  
        ?&gt;
                                          &lt;div class="product product-widget"&gt;
                                              &lt;div class="product-thumb"&gt;
                                              &lt;img src="&lt;?php echo $v-&gt;img;?&gt;" height="50" width="60" alt=""&gt;
                                              &lt;/div&gt;
                                              &lt;div class="product-body"&gt;
                                                  &lt;h3 class="product-price"&gt;&lt;?php echo $v-&gt;price;?&gt; &lt;span class="qty"&gt;x1&lt;/span&gt;&lt;/h3&gt;
                                                  &lt;h2 class="product-name"&gt;&lt;a href="#"&gt;&lt;?php echo $v-&gt;name;?&gt;&lt;/a&gt;&lt;/h2&gt;
                                              &lt;/div&gt;
                                              &lt;button class="cancel-btn" style="margin-right:8px;"&gt;&lt;a href="cart.php?rem_id=&lt;?php echo $v-&gt;id;?&gt;"&gt;&lt;i class="fa fa-trash"&gt;&lt;/a&gt;&lt;/i&gt;&lt;/button&gt;
                                            &lt;?php } 
  
                                      ?&gt;
                                      &lt;div class="shopping-cart-btns"&gt;
                                          &lt;a href="cart.php"&gt;&lt;button class="main-btn"&gt;View Cart&lt;/button&gt;&lt;/a&gt;
                                          &lt;a href="checkout1.php"&gt;&lt;button class="primary-btn" style="margin-left:15px;"&gt;Checkout &lt;i class="fa fa-arrow-circle-right"&gt;&lt;/i&gt;&lt;/button&gt;&lt;/a&gt;
                                      &lt;/div&gt;
                                      &lt;?php
  
        }
  
                                            else{
                                              echo '&lt;p style="color: red;"&gt;No Product is added in your cart&lt;/p&gt;';  
  
                                            }
  
  
                                            ?&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/li&gt;
  
  </code></pre>
  
  <p>I want to update the cart div when I click on <em>Add to cart.</em></p>