whare Posted February 18, 2008 Share Posted February 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
schilly Posted February 18, 2008 Share Posted February 18, 2008 is $id defined somewhere in counter.php? Quote Link to comment Share on other sites More sharing options...
whare Posted February 18, 2008 Author Share Posted February 18, 2008 define as in $id = $row["file_id"]; Or something else? Quote Link to comment Share on other sites More sharing options...
schilly Posted February 18, 2008 Share Posted February 18, 2008 If the first file yes and then it is passed into the counter.php as a GET variable and not defined again. Add: $id = $_GET['id']; in counter.php before the sql statement. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 edit: one sec.. Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 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()); ?> Quote Link to comment Share on other sites More sharing options...
whare Posted February 18, 2008 Author Share Posted February 18, 2008 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 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 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()); ?> Quote Link to comment Share on other sites More sharing options...
whare Posted February 18, 2008 Author Share Posted February 18, 2008 Still no good 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 hmmmm Im missing something somewhere I just carnt see it for the life of me lol Quote Link to comment Share on other sites More sharing options...
schilly Posted February 18, 2008 Share Posted February 18, 2008 Change WHARE to WHERE Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 Change WHARE to WHERE HAHA, wow I can't believe i didn't sight that. That should fix the problem, but it also the code you used in the begnning for this method wouldn't work. Quote Link to comment Share on other sites More sharing options...
whare Posted February 18, 2008 Author Share Posted February 18, 2008 HAHAHAHA I feel such a T*** now It works now Thanx Guys Quote Link to comment Share on other sites More sharing options...
phpSensei Posted February 18, 2008 Share Posted February 18, 2008 HAHAHAHA I feel such a T*** now It works now Thanx Guys I think you should fix your username, WHARE lol. Quote Link to comment Share on other sites More sharing options...
whare Posted February 18, 2008 Author Share Posted February 18, 2008 and this will be how I have made the problem by typing as if i was logging in to something/somewhere of all the stupid things todo well at least it works now thats the main thing Quote Link to comment Share on other sites More sharing options...
schilly Posted February 18, 2008 Share Posted February 18, 2008 haha. I saw it the first time around but thought you just changed it to that for fun. Quote Link to comment Share on other sites More sharing options...
whare Posted February 18, 2008 Author Share Posted February 18, 2008 haha. I saw it the first time around but thought you just changed it to that for fun. nope i just did not notice the typo well i will now take more care when typing that one Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.