Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/5581-hits-counter/
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.
Link to comment
https://forums.phpfreaks.com/topic/5581-hits-counter/#findComment-19917
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.
Link to comment
https://forums.phpfreaks.com/topic/5581-hits-counter/#findComment-20108
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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