Jump to content

Archived

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

lpxxfaintxx

Hits Counter

Recommended Posts

I've taken out some parts of the script to show you what's wrong. I am trying to make a hits counter but no matter what I do, it doesnt seem to be working :(

[code]
$viewid = $_GET["id"];
$result = mysql_query("SELECT * FROM registered_files WHERE viewid = '$viewid'");
$myrow = mysql_fetch_array($result);
$hits = $myrow['hits'] + 1;
$sql = "UPDATE registered_files SET hits='$hits' WHERE id=$viewid";

      $result = mysql_query($sql);?>[/code]

[code]
      <td>This image has been viewed: </td>
      <td><?php echo $hits ?>&nbsp;</td>[/code]

Shouldn't the hits +1 and update? Please help, thanks.

Share this post


Link to post
Share on other sites
[code]
$viewid = $_GET['id'];
...
...
$result  = mysql_query("UPDATE registered_files SET hits=hits+1 WHERE id = $viewid") or die (mysql_error());
[/code]

would be all you need to do to update the counter quickly. i've added: or die(mysql_error()) to let you know if there's some other problem.

Share this post


Link to post
Share on other sites
For the first line of the code you provided;

[code]$viewid = intval($_GET["id"]);[/code]

will be better for security ...

Share this post


Link to post
Share on other sites
I tried

[code]<?php $result2  = mysql_query("UPDATE registered_files SET hits=hits+1 WHERE id = '$viewid'") or die (mysql_error());
$myrow2 = mysql_fetch_array($result2);[/code]

but it says [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/lpxxfain/public_html/membersimage.php on[/quote]

There is a $result and $myrow somewhere else in the script so I had to make 2.

Thanks guys. I really don't know what I'd do without you.

Share this post


Link to post
Share on other sites

×

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.