Page 1 of 1

adding number of download and insert into mysql

Posted: Wed Aug 07, 2002 10:33 am
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

Posted: Wed Aug 07, 2002 10:56 am
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;
?>

Posted: Wed Aug 07, 2002 7:20 pm
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);

Posted: Wed Aug 07, 2002 7:55 pm
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