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
https://forums.phpfreaks.com/topic/235377-update-sql-database/
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
https://forums.phpfreaks.com/topic/235377-update-sql-database/#findComment-1209599
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.