Jump to content

Update SQL database


Larry101

Recommended Posts

Hello

 

I am updating a SQL database - basically adding to an account field as follows...

 

$sql1 = "select * from member where username = \"$owner\" limit 1  ";
        $result1 = mysql_query($sql1, $conn) or die(mysql_error());
        $row1 = mysql_fetch_assoc($result1);

        $total_commissions = $row1['total_commissions']; $total_commissions = $total_commissions + $_SESSION['cost_per_token']; //add to data
        $balance = $row1['balance']; $balance = $balance + $_SESSION['cost_per_token']; //add to data

      #--------------------------------------------------------------------------
      #Update db
$sql1 = "
         UPDATE member SET total_commissions = \"$total_commissions\", balance = \"$balance\"
         WHERE username=\"$owner\"
         ";
         $result1 = mysql_query($sql1, $conn) or die(mysql_error());

 

is there a way to add to the data from the UPDATE query? e.g;

 

$sql1 = "
         UPDATE member SET total_commissions = \"$total_commissions\ + $_SESSION['cost_per_token'] ", balance = \"$balance\ + $_SESSION['cost_per_token']"
         WHERE username=\"$owner\"
         ";

Link to comment
Share on other sites

Do you want to add the actual column value, or some variable "$total_commissions"?  You have correct syntax but if you want the column value then take out the '$'.

 

I think it's like (if total_commisions is not an integer than you need single quotes):

total_commissions = total_commissions + {$_SESSION['cost_per_token']}

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.