I have a download page which shows a table containing downloadable files like this.
----------------------------------------------
|filename | description | times downloaded |
----------------------------------------------
I have a datbase storing the filename(fname) and times downloaded (count). Embedded in a table cell is php code to lookup the filename, get the count and echo the count to display times downloaded.
When clicking the download link in the table (filename) I call another page (filename.php), this page opens the db, looks for the filename and increments the count by 1 then calling the file for download (using header)and finally including the original download page.
The problem is that although count updates properly and header does indeed call the download dialogue box, when redisplaying the downloads page either by using include or using the back button on browser, the count shown for the filename is not updated. Strangely refreshing the page via browser button does display the correct count?
My code is below.
My choose file to download page.
Expand|Select|Wrap|Line Numbers
- <?php
- $host="localhost";
- $user="root";
- $pass="";
- $conn=mysql_connect($host,$user,$pass);
- mysql_select_db("teg",$conn);
- ?>
- <html>
- <head><title>Downloads</title><base target="_self"></head>
- <body>
- <p align="center"><u><font size="5"><b>Downloads</b></font></u></p>
- <div align="center">
- <table border="1" width="74%" id="table1">
- <tr>
- <td align="center" width="86"><a href="nickint.php">Nickint</a></td>
- <td align="left" width="419" colspan="3"><font size="2">An interview with Nick Elizar, Grand
- Master & founder of World Nickelstick Eskrima Club
- <?php
- $sql="SELECT * FROM downs WHERE fname='nickint'";
- $result=mysql_query($sql,$conn) or die(mysql_error());
- $rows=mysql_num_rows($result);
- while($newarray=mysql_fetch_array($result))
- {
- $fname=$newarray['fname'];
- $count=$newarray['count'];
- echo 'Downloaded '.$count.' times.';
- }
- mysql_close($conn);
- ?>
- </font></td>
- </tr>
- </table>
- </div>
- <p align="center"> </p>
- </body>
- </html>
Expand|Select|Wrap|Line Numbers
- <?php
- $host="localhost";
- $user="root";
- $pass="";
- $conn=mysql_connect($host,$user,$pass);
- mysql_select_db("teg",$conn);
- // now search for entry
- $sql="UPDATE downs SET count=count+1";
- $result=mysql_query($sql,$conn) or die(mysql_error());
- mysql_close($conn);
- header("Location:nickint.rar");
- include("downloads.php");
- ?>
- Database is called teg,has one table called downs.
- Table has two fields fname and count.
- Can anyone please point me to how to get the update to display. the user needs to be returned to the download screen, perhaps to download another file. I guess that the next time the user returns to the site as a whole the corredct count will be displayed but why does it not display during the same viewing session.
- Thanks in advance for any help.