Jump to content

Download Counter Error


whare

Recommended Posts

Hay All

 

Right im trying to creat a download counter with not much luck at the moment here is my code

 



<?php
include ("includes/config.php");

// Make a MySQL Connection
mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$name") or die(mysql_error());

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM files_download order by file_id")
or die(mysql_error());  
echo "<table border='1' width='800'>";
while($row = mysql_fetch_array( $result )) {
$id = $row["file_id"];


echo "<tr>";
echo "<td width='100%' colspan='5'>file name ".$row['file_name']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='25%'>Date Uploaded ".$row['file_date']."</td>";
echo "<td width='25%'>File Size ".$row['file_size']."</td>";
echo "<td width='25%'>Requirements</td>";
echo "<td width='13%'>PHP: ".$row['file_php']."</td>";
echo "<td width='12%'>MySQL: ".$row['file_mysql']."</td>";
echo "</tr><tr>";
echo "<td width='100%' colspan='5'>Description ".$row['file_decription']."</td>";
echo "</tr><tr>";
echo "<td width='50%' colspan='2'>Download <b><font color='#FF0000'><a 

href='counter.php?id=$id'>Download</a></font></b></td>";
echo "<td width='50%' colspan='3'>No. Downloads ".$row['file_downloads']." </td>";
echo "</tr>";
}
echo "</table>";


?>


 

Not the best laid out code I no I just hope you can find your way through it enough to help

 

that file sends to counter.php

 


<?

include ("includes/config.php");

mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$name") or die(mysql_error());

$result = mysql_query("SELECT * FROM files_download WHARE file_id='$id'")
or die(mysql_error());  

while ($row = mysql_fetch_array($result))
{

$id1 = $row["file_id"];
$count = $row["file_downloads"];
$fileurl = $row["file_location"];
}
header('Location: '.$fileurl);

$result = mysql_query("UPDATE files_download SET file_downloads='$count'+1 WHERE file_id='$id1'")
or die(mysql_error());

?>

and here is the error I get

 

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'file_id=''' at line 1

 

 

now as you should be able to work out from the code i intend to have multiple files for download and I would like it all to be maintaind from one file

 

 

anyway hope somebody has an idea about where is am going wrong

 

Thanx

Link to comment
https://forums.phpfreaks.com/topic/91788-download-counter-error/
Share on other sites

try

 

<?php

include ("includes/config.php");

mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$name") or die(mysql_error());

$result = mysql_query("SELECT * FROM files_download WHARE file_id='$id'")
or die(mysql_error());  
$row = mysql_fetch_array($result);

$id1 = $row["file_id"];
$fileurl = $row["file_location"];

header('Location: '.$fileurl);

$result = mysql_query("UPDATE files_download SET file_downloads = file_downloads +1 WHERE file_id='$id1'")
or die(mysql_error());

?>

still giving me an error for both ideas

 

with  schilly

$id = $_GET['id'];

 

i get this error

 

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'file_id='1'' at line 1

 

note the "1" at the end of the file_id that is at least 1 improvement :)

 

however phpSensei if i use your code i get the original error :(

still giving me an error for both ideas

 

with  schilly

$id = $_GET['id'];

 

i get this error

 

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'file_id='1'' at line 1

 

note the "1" at the end of the file_id that is at least 1 improvement :)

 

however phpSensei if i use your code i get the original error :(

 

 

Where do you define the $id in the first place?

 

$result = mysql_query("SELECT * FROM files_download WHARE file_id='$id'")

 

Try our methods combined

 

<?php

include ("includes/config.php");

mysql_connect("$host", "$user", "$pass") or die(mysql_error());
mysql_select_db("$name") or die(mysql_error());

$id = $_GET['id'];
$result = mysql_query("SELECT * FROM files_download WHARE file_id='$id'")
or die(mysql_error());  
$row = mysql_fetch_array($result);

$id1 = $row["file_id"];
$fileurl = $row["file_location"];

header('Location: '.$fileurl);

$result = mysql_query("UPDATE files_download SET file_downloads = file_downloads +1 WHERE file_id='$id1'")
or die(mysql_error());

?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.