gizaim Posted February 11, 2007 Share Posted February 11, 2007 Hello! Long time reader, first time poster I have a project iv been working on for a while now which, among other things, lets users rate a particular game. The rating system works well, but when clicked on it will increment the database by two. Also, a download counter is also used on a seperate page, also incrementing the value of a data field in the database by two. The only catch: If the user at that computer has already clicked on the link before, the database will correctly increment by one! Here is a piece of my code for the download counter: //the primary update query mysql_query("UPDATE games SET dwnlds = dwnlds+1 WHERE gamename LIKE '$search'"); //query to output info related to a search $query3 = mysql_query("SELECT * FROM games WHERE gamename LIKE '%$search%' LIMIT 1"); while ($row = @mysql_fetch_array($query3)) { $variable1=$row["gamename"]; $variable7=$row["link"]; //then proceeds to output a few links to the screen, no database querys are made after this point } an example of this page can be seen at http://www.gizaim.com/download.php?search=icy%20tower Thanks in advance for the help, and let me know if you require more information. Iv skimmed through my code for weeks with no clue as to the problem ??? Quote Link to comment https://forums.phpfreaks.com/topic/37983-solved-query-increments-database-twice/ Share on other sites More sharing options...
fenway Posted February 11, 2007 Share Posted February 11, 2007 I'm not sure what you mean... only way is for this to run twice (e.g. POSTed twice). Quote Link to comment https://forums.phpfreaks.com/topic/37983-solved-query-increments-database-twice/#findComment-182276 Share on other sites More sharing options...
btherl Posted February 12, 2007 Share Posted February 12, 2007 Typically this problem will be due to either the browser making two requests (perhaps for pre-caching), or due to code being executed a second time by accident (perhaps via include() ?). If you have access, check your server logs and see what requests were made. If there are two requests causing the two updates, then you have found the problem. IF a single request causes the two updates, then try adding some debugging output right next to your code that does the update. You should see that debugging output twice in the output of the script. Another possibility for double execution is that you use $query3 later on by accident, instead of $query5 or $query7 or whichever other names you use. Quote Link to comment https://forums.phpfreaks.com/topic/37983-solved-query-increments-database-twice/#findComment-182354 Share on other sites More sharing options...
gizaim Posted February 12, 2007 Author Share Posted February 12, 2007 Typically this problem will be due to either the browser making two requests (perhaps for pre-caching), or due to code being executed a second time by accident (perhaps via include() ?). If you have access, check your server logs and see what requests were made. If there are two requests causing the two updates, then you have found the problem. IF a single request causes the two updates, then try adding some debugging output right next to your code that does the update. You should see that debugging output twice in the output of the script. Another possibility for double execution is that you use $query3 later on by accident, instead of $query5 or $query7 or whichever other names you use. Unfortunately I do not have access to the server logs. I checked again to make sure that i am not using the same query name twice, and i am not. Actually, on the entire page I make only 2 querys on the database and only use php in two small sections. So i tried adding a third query, and sure enough, the database updates by three now. I can show you the second query on the page and maybe someone will see something i don't between the two. <?php $query = mysql_query("SELECT * FROM `games` ORDER BY 'dwnlds' DESC LIMIT 3"); while ($row = @mysql_fetch_array($query)) { $variable1=$row["gamename"]; $variable2=$row["dwnlds"]; $variable3=$row["link"]; echo ("<a href=http://www.gizaim.com/desc.php?search=$variable3><font color='#FFFFFF' face='verdana' size='2'><b>$variable1</b></font></a><br>"); echo ("<img src='/images/dark.gif' width='50' height='5'><br>"); echo ("<a href=http://www.gizaim.com/desc.php?search=$variable3><img border='1' style='border-color:#000000' align='center' src='/demos/images/$variable1 _3.jpg' title='$variable1' alt='$variable1'></a><br>"); echo ("<font face='verdana' size='1' color='#FFFFFF'><i>$variable2 downloads</i></font><br>"); } ?> It really couldn't be any more straighforward, which is why I am so confused. Thanks a lot for the help though! Quote Link to comment https://forums.phpfreaks.com/topic/37983-solved-query-increments-database-twice/#findComment-182779 Share on other sites More sharing options...
gizaim Posted February 12, 2007 Author Share Posted February 12, 2007 Well i think i finally figured it out...google adwords is causing the page to load twice. If i remove the ads from the page, the problem is solved. Now i just have to figure out how to fix this one as adwords is how all the income on the site is generated. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/37983-solved-query-increments-database-twice/#findComment-182906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.