Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › need help with a simple php/mysql download tracker
New Posts  All Forums:Forum Nav:

need help with a simple php/mysql download tracker

post #1 of 2
Thread Starter 
my goal is to track who is downloading from my server and what they are downloading, and when. I am trying to gather the info for the logged in user, and the file name, in this instance im using movies for an example, and record it to a sql table where i can easily reference it with php my admin.

so as of now i have 3 tables set up, one for users, holding all the registration data for my site, username, user id, password email... etc. one for the files holding all the file names with a unique id for each file, and one to log the info to, download tracker, to save the username, user id, email adress, file they are downloading, and a timestamp of when they started the download.

so i have set up download links with the movie name in plain text and the movie id as a url variable like this:
Code:
<a href="/movies/moviehandaler.php$=1" alt="" >movie x </a>
<a href="/movies/moviehandaler.php$=2" alt="" >movie y </a>
<a href="/movies/moviehandaler.php$=3" alt="" >movie z </a>

they will then pass through to a handler page to log the information and pass through to the dowload like this:
Code:
<?php
$user_info = ('username', 'email', 'user_id' FROM `users` WHERE 'user_id' = $session_user_id); //is this right?
$movie_id = get['id'];
$movie_info = ('movie_name' FROM `movies` WHERE '$movie_id' = 'movie_id'); // is this right?
mysql_query("INSERT INTO `download_tracker` (user_id, username, email, file, date) VALUES('$user_info['user_id']', '$user_info['username']', '$user_info['email']', '$movie_info['movie_name']', 'time', ) ") or die(mysql_error());  
header('Location: /movies/<?php print $movie_info ?>'); //is this even posible?
?>

I need help to fix the handaler page so it works... i know im fairly close, i just cant seem to get it right, any help would be greatly apreciated and rep will be given for anyone who can get me closer to my goal... thanks for reading through this far. thumb.gif
Edited by THC Butterz - 7/23/13 at 10:43am
post #2 of 2
Your links would look like this in php echoed out, just loop through them
Code:
echo '<a href="/movies/moviehandaler.php?id=$movie_id" alt="" >' . $movie_title . '</a>'

then it would render in html like
Code:
<a href="/movies/moviehandaler.php?id=1" alt="" >movie x </a>
Code:
//I'm guessing $user_info is selecting that information so you'd need something like:
$user_info = "SELECT userame, email, user_id FROM users WHERE user_id = $_SESSION['userID']";

//then you'd need to run the query
mysqli_query($databaseConnection, $user_info) //I believe this is how you query a db in mysqli, I don't ever use it, I stick with PDO as I find it easier 

//For the movie id do
$movie_id =  $_GET['id'];

//Fix the query similair to the way I showed for user info

//For the header you do not need php tags as you are already in php so it would be something like
header('Location: /movies/' . $movie_id);

I hope that gives you some idea.
My System
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 @ Stock Asus P6T ATI HD5870 OCZ 6GB 1333mhz 
Hard DriveHard DriveOptical DriveCooling
Samsung 840 Evo Caviar Black 640GB LG DVD Drive Cm Hyper 212+ 
CoolingOSMonitorPower
Arctic Cooling Accelero Twin Turbo II Windows 7 64bit ASUS VW246H Corsair HX850 
Case
CM 690 II Adavanced 
  hide details  
Reply
My System
(16 items)
 
  
CPUMotherboardGraphicsRAM
i7 920 @ Stock Asus P6T ATI HD5870 OCZ 6GB 1333mhz 
Hard DriveHard DriveOptical DriveCooling
Samsung 840 Evo Caviar Black 640GB LG DVD Drive Cm Hyper 212+ 
CoolingOSMonitorPower
Arctic Cooling Accelero Twin Turbo II Windows 7 64bit ASUS VW246H Corsair HX850 
Case
CM 690 II Adavanced 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › need help with a simple php/mysql download tracker