title: update session variables inside Javascript
body: <p>I have a page called index.php where i have all my php functions, javascripts and html tags.
  Upon button click (add to cart) event i want to call a php function ( addtToCart($itemID) ) to update session variables. Can you tell me how to implement this in my code ? </p>
  
  <pre><code>&lt;?php
  session_start();
  $_SESSION['Mid']=""; 
  $_SESSION['$UserName']="test"; ?&gt;
  
  //html part
  &lt;button id='cart' 
  onclick="&lt;script&gt;idk how to call my function here&lt;/script&gt;"
  class="w3-button"&gt;ADD TO CART&lt;/button&gt;
  
   //my php function
  &lt;?php
    function addToCart($Mid){
      if(!isset($_SESSION['$UserName'])){
              header('Location:signin.html');
      }
      $_SESSION['Mid'].="+".$Mid;
      echo "&lt;script type='text/javascript'&gt;alert(\"ADDED TO CART\");&lt;/script&gt;";
    }
  ?&gt;
  </code></pre>