title: How to auto update database mysql using javascript in html
body: <p>I want to auto update my database when the countdowntimer is == 0 or &lt; 0 without reloading the page. Only a certain block will be reload or reload the script/code. How can i auto update my database in mysql when the distance is &lt; 0? I try the reload(); and .load(location.href("#")); But they reload the page. </p>
  
  <p>I use PHP as my backend</p>
  
  <p>In JAVASCRIPT</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;     
      function createCountDown(elementId, date) {
  
      var countDownDate = new Date(date).getTime();
  
      var x = setInterval(function() {
  
        var now = new Date().getTime();
  
        var distance = countDownDate - now;
  
        var days = Math.floor(distance / (1000 * 60 * 60 * 24));
        var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  
        document.getElementById(elementId).innerHTML = days + 'd ' +
                                                       hours + 'h ' +
                                                       minutes + 'm ' + 
                                                       seconds + 's ';
  
        if (distance &lt; 0) {
          clearInterval(x);
          document.getElementById(elementId).innerHTML = "Expired";
        }
      }, 1000);
  }
  </code></pre>
  
  <p></p>