I am trying to add a value ($credit
) 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 $credit
and then adds it for some reason. I just want it to add it. The code I am using is:
mysql_query("update $table set earnings = earnings +$credit where username = ('$member')");
I want to add the value of $credit
to the field called earnings. Does somebody know why it is doubling the value of $credit
before adding it?
Update
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 query
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.