Jump to content


Photo

Hits Counter


  • Please log in to reply
4 replies to this topic

#1 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 23 March 2006 - 12:07 PM

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 :(

$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);?>

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

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

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 23 March 2006 - 12:29 PM

$viewid = $_GET['id'];
...
...
$result  = mysql_query("UPDATE registered_files SET hits=hits+1 WHERE id = $viewid") or die (mysql_error());

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.

"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 tacnev

tacnev
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 March 2006 - 12:45 PM

For the first line of the code you provided;

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

will be better for security ...

#4 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 23 March 2006 - 08:17 PM

I tried

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


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.

#5 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 23 March 2006 - 11:14 PM

Could it be that theres 2 mysql querys in one script?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users