adding number of download and insert into mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gilbertwang
Forum Commoner
Posts: 32
Joined: Sun Jun 30, 2002 11:08 pm
Location: Calgary

adding number of download and insert into mysql

Post by gilbertwang »

I am trying to keep track of the number of downloads, how can I write a script that will insert a +1 to a field(totaldownload) in mysql when the user has download a certain file.

lets pretend the file is in the folder( screen/test.exe)
And I have a download link as

Code: Select all

print "<a href="$screenlink">Download</a><br><br><br>\n";
The download will call the screen/test.exe, and I need to add a +1 whenever the user download the file in mysql field(totaldownload)

Thanks
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

you might wanna have a page called download.php
then send your download like to it like
download.php?file=file.exe

in the download.php you can do a query which add 1 to db.

here is what i use:

Code: Select all

<?php
include("db.inc");
$getfromdb = mysql_query("SELECT downloads from q_downloads where ID='1'") or die ("error on first query");
$gety = mysql_fetch_array($getfromdb);
$new2 = $gety&#1111;downloads] + 1;
$newdl = mysql_query("UPDATE q_downloads SET downloads='$new2' where ID='1'") or die ("error on second query!");
if(IsSet($file))
&#123;
header("Location:http://$file");
&#125;
?>
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

yea, download.php would work, and just use the query:

Code: Select all

$query = "UPDATE table SET totaldownloads = totaldownloads + 1 WHERE file='$file'";
mysql_query($query);
User avatar
chiefmonkey
Forum Commoner
Posts: 25
Joined: Sat Apr 20, 2002 5:21 am
Location: Glasgow UK

Post by chiefmonkey »

I wrote a download tracker class for PHP/MySQL with the added option of being able to generate a graph to for your download stats(you will need GD installed for this), you can get it at http://www.experimentalmonkey.co.uk/code.php

George
Post Reply