Jump to content

[SOLVED] Query Increments Database Twice


gizaim

Recommended Posts

Hello!  Long time reader, first time poster  :D

 

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  ???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.  :-\

Link to comment
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.