mysql query adding to a decimal doubles value of the addend for some reason

KimmyG

New Member
I am trying to add a value (\[code\]$credit\[/code\]) to the value of a decimal (9,2 max length) field in a mysql database. The problem is that when I do this, it doubles the \[code\]$credit\[/code\] and then adds it for some reason. I just want it to add it. The code I am using is:\[code\]mysql_query("update $table set earnings = earnings +$credit where username = ('$member')");\[/code\]I want to add the value of \[code\]$credit\[/code\] to the field called earnings. Does somebody know why it is doubling the value of \[code\]$credit\[/code\] before adding it?UpdateI echoed the query and I saw that the value that it was adding was indeed the right value of $credit. And then I checked the database under earnings and it had added the right value. I don't know why it automatically fixed itself. I think it's possible that it used to run twice because I have the script running on ajax every 5 seconds with prototype. After $credit is added successfully I make an entry into another database saying that it was added and then before I have:\[code\]if(database says that the credit was added) { exit;}else{ run the add $credit query\[/code\]So maybe, the script wouldn't have enough time to finish the whole thing in 5 seconds so it would never tell the other database that the $credit addition was complete so it would add it again and then for some reason have enough time to write it completed it the second time? I don't know, but thanks anyways for the help.I echoed the query and I saw that the value that it was adding was indeed the right value of $credit. And then I checked the database under earnings and it had added the right value. I don't know why it automatically fixed itself. I think it's possible that it used to run twice because I have the script running on ajax every 5 seconds with prototype. After $credit is added successfully I make an entry into another database saying that it was added and then before I have if(database says that the credit was added){ exit;}else{ run the add $credit queryso maybe, the script wouldn't have enough time to finish the whole thing in 5 seconds so it would never tell the other database that the $credit addition was complete so it would add it again and then for some reason have enough time to write it completed it the second time? I don't know, but thanks anyways for the help.
 
Back
Top