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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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