title: How to create a download file count using php mysqli
body: <p>I have a download.php file which enables me download my files from database, I need help to alter it to count the number of times a file has been downloaded on my webpage.</p>
  
  <pre><code>download.php
  &lt;?php
  require_once './includes/connection.php';
  $conn = dbConnect('read');
  //if(isset($_GET['id'])){}
  $songid = $_GET['id'];
  $sql = 'SELECT * FROM homemp3 WHERE song_id ='.$songid;
  $result = $conn-&gt;query($sql);
  $row = mysqli_fetch_array($result);
  $mp3 = 'homemp3/' .$row['filename'];
  if(file_exists($mp3)) {
  header('Content-Type: audio/mpeg');
  header('Content-Disposition: attachment; filename="' .basename($mp3). '"' 
  );
  header('Content-length: '. filesize($mp3));
  header('Cache-Control: no-cache');
  header('Content-Transfer-Encoding: binary'); 
  readfile($mp3);
  exit;
  }
  
  download_script.php
  &lt;div class="col-12"&gt;
  &lt;div class="media"&gt;
  &lt;img src="./images/&lt;?= $mainImage; ?&gt;" alt="PowerBeatz" width="300" 
  height="300" /&gt;
  &lt;div class="media-body"&gt;
  &lt;h5 class="mt-0"&gt;&lt;span class="title"&gt;&lt;?php echo $row['song']; ?&gt;&lt;/span&gt; 
  &lt;/h5&gt;
  &lt;?php echo $row['artist']; ?&gt;
  &lt;div class="play"&gt;
  &lt;a href="download.php?id=&lt;?php echo $row['song_id']; ?&gt;" class="btn btn- 
  primary"&gt;&lt;i class="fa fa-download"&gt;&lt;/i&gt;&lt;/a&gt;
  &lt;/div&gt;
  &lt;div&gt;
  
  &lt;p&gt;Total Downloads:&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>