Larry101 Posted May 2, 2011 Share Posted May 2, 2011 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\" "; Quote Link to comment https://forums.phpfreaks.com/topic/235377-update-sql-database/ Share on other sites More sharing options...
fugix Posted May 2, 2011 Share Posted May 2, 2011 yes, you're basically doing the same thing..however storing them in vars first makes for neater queries. Quote Link to comment https://forums.phpfreaks.com/topic/235377-update-sql-database/#findComment-1209597 Share on other sites More sharing options...
Maq Posted May 2, 2011 Share Posted May 2, 2011 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']} Quote Link to comment https://forums.phpfreaks.com/topic/235377-update-sql-database/#findComment-1209599 Share on other sites More sharing options...
Larry101 Posted May 2, 2011 Author Share Posted May 2, 2011 Thanks guys.. I am reassured Quote Link to comment https://forums.phpfreaks.com/topic/235377-update-sql-database/#findComment-1209644 Share on other sites More sharing options...
fugix Posted May 2, 2011 Share Posted May 2, 2011 Glad we could help. Quote Link to comment https://forums.phpfreaks.com/topic/235377-update-sql-database/#findComment-1209667 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.