thewhat Posted February 6, 2008 Share Posted February 6, 2008 Hey all. Got a slight problem here. I've got some variables that use a number of different operators for some math functions on my site. Now when I echo the variable on a page, it does the calculation just fine. HOWEVER, when I query the DB to update a table with the information it doubles. 1 becomes 2, 2 becomes 4 and so on and so forth. Here is the code: $add = ($userdata['example1'] * 25); $add2 = ($userdata['example2]); $add3 = $add2 + $add; echo $add; $result = dbquery("UPDATE ".$db_prefix."users SET example4='$add3' WHERE user_id='".$userdata['user_id']."'"); Now, $userdata['example1'] would be 4 * 25 and the query should insert '100' into table example4. But it inserts '200'. This just started happening. A few days ago it was fine as I have not tinkered with the code at all. Can anyone help me? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 6, 2008 Share Posted February 6, 2008 You're echoing $add, but you're using the value of $add3 in the update. What does that contain? What's the value of $add2? Ken Quote Link to comment Share on other sites More sharing options...
thewhat Posted February 6, 2008 Author Share Posted February 6, 2008 add2 is simply one of the tables I have in my DB. I added it to test something out. But this is a widespread issue among ALL my codes where math is required. Everything is doubling up. Quote Link to comment Share on other sites More sharing options...
dprichard Posted February 6, 2008 Share Posted February 6, 2008 if you echo $add, $add2 and $add3 what do you see? You are inserting $add3 so I would see what the value of that is by echoing it out first. If you $add shows the value you want to update your database with then why don't you just SET example4 = '$add' instead of '$add3' Quote Link to comment Share on other sites More sharing options...
thewhat Posted February 6, 2008 Author Share Posted February 6, 2008 It replaces anything I have in the table with the sum. So in the table I'd have like 500, since $add equals 100, it will just replace it. $add3 is so that it add's 100 + whatever is in $add2. Anyway, here it happens again: $addition = ($userdata['user_exmp'] + 1); $dbquery = "UPDATE ".$db_prefix."users SET user_exmp1= '$addition' WHERE user_id='".$userdata['user_id']."'"; Instead of adding 1, it adds 2. And it goes on to falter on all my codes. And it only started doing it last night. Weirdest thing ever!! Quote Link to comment Share on other sites More sharing options...
dprichard Posted February 6, 2008 Share Posted February 6, 2008 $add3 is the result of $add2 + $add so if $add = 100 and when you insert $add3 you are getting 200 then I would assume that $add2 = 100. What are you getting when you echo out these variables onto the page? Quote Link to comment Share on other sites More sharing options...
thewhat Posted February 6, 2008 Author Share Posted February 6, 2008 $add2 in my DB is actually 0 at the moment. I changed it to see what was going on. So: $add = 100 $add2 = 0 $add3 should be 100. But nope. The damn thing doesn't want to cooperate. Quote Link to comment Share on other sites More sharing options...
dprichard Posted February 6, 2008 Share Posted February 6, 2008 Are those the results that echo out after you do the math at the top? Quote Link to comment Share on other sites More sharing options...
thewhat Posted February 6, 2008 Author Share Posted February 6, 2008 Yup. Echoing the variables cause no problem. It's only when the query goes through does it act weird. Quote Link to comment Share on other sites More sharing options...
schilly Posted February 6, 2008 Share Posted February 6, 2008 if you echo the query string it is correct as well? Quote Link to comment Share on other sites More sharing options...
thewhat Posted February 6, 2008 Author Share Posted February 6, 2008 Indeed. Quote Link to comment Share on other sites More sharing options...
thewhat Posted February 6, 2008 Author Share Posted February 6, 2008 Hrm. It's working now. See what I mean? Quote Link to comment 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.