I have a table in my database where I want to track the number of downloads for each uploaded file in my website. I have succeeded in inserting user details after a successful download of a file. Each user that downloads a file the user ip address is save in my database tbl (All_downloads) and the filename the user downloaded. I have a different table (Songs) where I stored all uploaded files and I added a column in the table name "DOWNLOAD COUNTER", now I want to fetch the total number of downloads from tbl ALL_downloads and INSERT the total number into tbl "songs" (I WANT IT TO BE GROUP BY THE SONG NAME).
if (isset($_GET['name']) && basename($_GET['name']) == $_GET['name']) {
$name = $_GET['name'];
$userip = $_SERVER['REMOTE_ADDR'];
$query = "SELECT * FROM songs_download_counter WHERE name='$name' && ip='$userip'";
$result = mysqli_query($con,$query);
if($result->num_rows==0){
$insertquery="INSERT INTO songs_download_counter SETip='$userip', name='$name'";
mysqli_query($con,$insertquery) or die (mysqli_error($con));
} else {
$row=$result->fetch_assoc();
if(!preg_match('/'.$userip.'/i', $row['ip'])) {
$newip = $_SERVER['REMOTE_ADDR'];
$updatequery="UPDATE songs_download_counter SET ip='$newip', name='$name' WHERE name='$name'";
mysqli_query($con,$updatequery) or die (mysqli_error($con));
}
}