Jump to content

Some operator issues


thewhat

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/89794-some-operator-issues/
Share on other sites

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'

 

 

Link to comment
https://forums.phpfreaks.com/topic/89794-some-operator-issues/#findComment-460151
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/89794-some-operator-issues/#findComment-460154
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.