title: fetch dashboard count from database using php jquery ajax
body: <p>I'm trying fetch data count from database to HTML <code>div</code> using PHP, jQuery and AJAX, but code below is not working.</p>
  
  <p>I just started learning ajax please help. Thank you!</p>
  
  <p><a href="https://i.stack.imgur.com/fJPeC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fJPeC.png" alt="enter image description here"></a></p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>            &lt;div class='col-lg-3 col-md-6'&gt;
                  &lt;div class='panel panel-primary'&gt;
                      &lt;div class='panel-heading'&gt;
                          &lt;div class='row'&gt;
                              &lt;div class='col-xs-3'&gt;
                                  &lt;i class='fa fa-microphone fa-5x'&gt;&lt;/i&gt;
                              &lt;/div&gt;
                              &lt;div class='col-xs-9 text-right'&gt;
                                              &lt;!-- here i want to fetch result --&gt;
                                              &lt;div id="leadmonth"&gt;&lt;/div&gt;
                                  &lt;div&gt;Total Leads&lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  </code></pre>
  
  <p><strong>Jquery</strong></p>
  
  <pre><code>$(document).ready(function() {
  
          $.ajax({
              type:'POST',
              url:'php_action/resourceqareportdashboardcount.php',
              dataType : 'json',
              success:function(html){
                  $('#leadmonth').html(html);
              }
  
  });
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php
  // This Month Count
  require_once 'db_config.php';
  $output= '';
  $sql = "SELECT * FROM leads WHERE YEAR(leadcreationdate) = YEAR(NOW()) AND MONTH(leadcreationdate)=MONTH(NOW())";
  $query = $connect-&gt;query($sql);
  $totalleads = mysqli_num_rows($query);
  
          if ($monthtotalleadscount &gt; "0") {
              $output = "&lt;div class='huge'&gt;$totalleads&lt;/div&gt;";
          } else {
              $output =  "&lt;div class='huge'&gt;0&lt;/div&gt;";
          }
  
  // database connection close
  $connect-&gt;close();
  
  echo json_encode($output);
  </code></pre>