lpxxfaintxx Posted March 23, 2006 Share Posted March 23, 2006 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 ?> </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 More sharing options...
redbullmarky Posted March 23, 2006 Share Posted March 23, 2006 [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 More sharing options...
tacnev Posted March 23, 2006 Share Posted March 23, 2006 For the first line of the code you provided;[code]$viewid = intval($_GET["id"]);[/code]will be better for security ... Link to comment https://forums.phpfreaks.com/topic/5581-hits-counter/#findComment-19922 Share on other sites More sharing options...
lpxxfaintxx Posted March 23, 2006 Author Share Posted March 23, 2006 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 More sharing options...
lpxxfaintxx Posted March 23, 2006 Author Share Posted March 23, 2006 Could it be that theres 2 mysql querys in one script? Link to comment https://forums.phpfreaks.com/topic/5581-hits-counter/#findComment-20140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.