List:MySQL and PHP« Previous MessageNext Message »
From:Skip Evans Date:February 12 2007 4:50pm
Subject:Interger values adding too much
View as plain text  
Hey all,

I have the following code block:

// get the number of points for this action
$sql="SELECT points FROM bsp_story_points WHERE 
action='$action'";
$result=mysql_query($sql);
if(mysql_errno()!=0)
bsp_SystemError("$sql<br>".mysql_error()."<br>",__FILE__,__LINE__); 

$row=mysql_fetch_assoc($result);
$pts=$row['points'];
echo "<br/>points to add:$pts";

// update the user's record with the new ponts.
$sql="UPDATE users SET points = (points + $pts) 
WHERE id=$uid";
echo "<br>SQL:$sql";
$result=mysql_query($sql);
if(mysql_errno()!=0)
 
bsp_SystemError("$sql<br>".mysql_error()."<br>",__FILE__,__LINE__); 

echo "<br/>points added";
exit;

And here is the output from the echo statements:

points to add:50
SQL:UPDATE users SET points = (points + 50) WHERE 
id=9252
points added


Now, I checked the value right before the UPDATE 
call, and it was 700. I am absolutely certain of 
this, but the value in the points column for the 
table users after the UPDATE runs is 800, not 750 
as it should be.

I've been running tests on this for two days and 
am completely baffled! I have tried this an 
embarrassing number of times, and it always adds 
either 100 or 150 points instead of the 50 points 
I think it should.

Any help on this would reward you with psychic 
pizzas with everything beamed your way.

I'm desperate for a solution to this as it is 
supposed to go into production today.

Thanks tons!
Skip

-- 
Skip Evans
Big Sky Penguin, LLC
61 W Broadway
Butte, Montana 59701
406-782-2240
http://bigskypenguin.com
=-=-=-=-=-=-=-=-=-=
Check out PHPenguin, a lightweight and
versatile PHP/MySQL development framework.
http://phpenguin.bigskypenguin.com/
Thread
Interger values adding too muchSkip Evans12 Feb