Jump to content

need help with a simple php/mysql download tracker


thcbutterz

Recommended Posts

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:

<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:

<?php
$user_info = ('username', 'email', 'user_id' FROM `users` WHERE 'user_id' = $session_user_id); //is this right?
$movie_id = get['']; //how would i grab the number from the url after "$="
$movie_info = ('movie_name' FROM `movies` WHERE '$movie_id' = 'movie_id'); // is this right?
mysql_query(INSERT '$user_info', '$movie_info', 'time', INTO `download_tracker`); // I know this is wrong, how do i fix it?
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.

Link to comment
Share on other sites

 

​thanks for this, its been a while since i played with php and needed a refresher, so this would be more accurate right?

<?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?
?>

Link to comment
Share on other sites

You have not connected to the database as far as I am aware, so you need to do that first.

 

Secondly, you are not executing the MySQL queries, just merely assigning them to a variable.

 

You need to look into PHP a bit more look at $_GET.

 

Then you need to move away from MySQL and look to MySQLi also, so read up on that too.

Link to comment
Share on other sites

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.