Jump to content

Recommended Posts

Hi Guys,

 

on my site when a user goes to the "downloads.php" page i update mysql to say downloads+1 to increment the number of downloads each time (but saying that not everyone who goes to the downloads page downloads something)

 

the code is pretty basic:

 

downloads.php

 

     // start by grabbing the id...//////////////////////////////////////////////////
     $id = $_GET['id'];	
     
     // get the file...///////////////////////////////////////////////////////////////////
     $query1 = "SELECT * FROM `uploads` WHERE `id`='$id'"; 
     $result1 = mysql_query($query1);
     $row = mysql_fetch_array($result1);
     
     $file_id = $row['file_id']; 
     $file_name = $row['file_name'];
     
     // update the hit counter...////////////////////////////////////////////////////////
     mysql_query("UPDATE `uploads` SET `downloads`=`downloads` + 1 WHERE `id`='$id'");

 

i was thinking a better way would be to place a button there when pressed the download box pops up and THEN it increments mysql but i'm not entirely sure where to go from there i can do the buttons ok:

 

<input type="submit" name="submit" value="downlod" />

 

so when the button is pressed the downloads starts (it's not a specific filename) so the name of the downloaded file changes depending on what the uploader has called it kinda thing.

 

any help would be great.

 

cheers

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/54283-counting-the-number-of-downloads/
Share on other sites

Try have a javascript popup that links straight to the file, see the code below:

if (isset($_POST['submit'])) {
?>
<script type="text/javascript">
window.open("http://www.yourdomain.com/file/link.exe");
</script>
<?
     // start by grabbing the id...//////////////////////////////////////////////////
     $id = $_GET['id'];	
     
     // get the file...///////////////////////////////////////////////////////////////////
     $query1 = "SELECT * FROM `uploads` WHERE `id`='$id'"; 
     $result1 = mysql_query($query1);
     $row = mysql_fetch_array($result1);
     
     $file_id = $row['file_id']; 
     $file_name = $row['file_name'];
     
     // update the hit counter...////////////////////////////////////////////////////////
     mysql_query("UPDATE `uploads` SET `downloads`=`downloads` + 1 WHERE `id`='$id'");}
?>

Try if this works or not, but I am not confident, just make sure the popup links to your file.

Ted

Hi Guys,

 

thanks for the input how hard is ajax? lol the only thing is i don't know the names of the files uploaded i couldn't say : a specificname.doc it would depend on what the user has uploaded would i just stick it in a variable?

 

cheers

 

Graham

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.