Well, first you need to change the movieâs HREF. Your current version:
href="/movies/moviehandaler.php$=1" This sends the link to the moviehandler.php file, but, does not pass the movie ID correctly. It should be more like this:
href="/movies/moviehandaler.php?id=1"
What this change does is pass the number â1â into the posted variable called âidââŚ
Inside the moviehandaler.php code, the first thing you do is âGETâ the id number so you can use it.
Something like:
$current_movie=$_GET[âidâ]; (This pulls the posted variable named âidâ and gets itâs value.
Next, you have the movie id at this point and you can do the rest of the tracking. Now on to that part.
Your current code:
<?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?
?>
This is a bit mixed up, but basically correct. It should be more like this: (I added some comments for you)
[php]
<?php
$movie_id = get['id']; // Grab the movie id passed from the link...
// Here you would have to pull the data you want to store that is not the movie ID.
// So, items like email and username would be needed if you want to store it in the DB table...
// Create a query to use to store into the database table
$query = "INSERT INTO download_tracker (username, email, user_id, movie_id, movie_name) VALUES ($username, $email, $user_id, $movie_id, $movie_name)";
// Store the data using the query to save the logging info...
mysql_query($query) or die(mysql_error()); // Note if there is an error it displays it and dies...
header('Location: /movies/<?php print $movie_info ?>'); //is this even posible?
?>
[/php]
Now, there is a couple of parts that I did not explain. Usually when someone logs into your site, you save the info about them into SESSION variables. This is done once the username and password have been checked and made sure they are a valid user. Then, you would save things like username and email into SESSION variables. Then, anywhere in your site that you need to use these, you would just use the SESSION variable to place them where needed. So, if you had done that during the log in process, the query would be more like this:
$query = âINSERT INTO download_tracker (username, email, user_id, movie_id, movie_name) VALUES ($_SESSION[âusernameâ], $_SESSION[âemailâ], $_SESSION[âuser_idâ], $movie_id, $movie_name)â;
This saves a lot of time as you do NOT have to run a query to get their info, it was already stored during login time. If you do not do that, you must do a query using their user_id on the user DB table and load these variables with the correct data. (I noted that in the codeâŚ)
Well, that should get you started. Let us know if you need further helpâŚ