PHP Minus 2 variables for value
<p>I have a page that when data is posted to it inserts the value into my DB.</p>

<p>Im trying to get a sum of all the values from the DB before hand, then insert the value, and then take the SUM away from the value inserted if this makes sense? </p>

<pre><code>$totalquery = mysql_query("SELECT SUM(bill) FROM `outgoings` WHERE outgoings.user_id = '$uid'") or die(mysql_error());
$totalresult = mysql_fetch_array($totalquery);          
$uid = $_SESSION['oauth_id'];
$id = $_POST['col-id'];
$sanitized_monthly_income = mysql_real_escape_string($_POST['monthly-income']);
mysql_query("INSERT INTO income (id, user_id, monthly_income) VALUES ('$id', '$uid', '$sanitized_monthly_income') ON DUPLICATE KEY UPDATE monthly_income = VALUES(monthly_income)");
echo $sanitized_monthly_income - $totalresult["SUM(bill)"];
</code></pre>

<p>This is the error I receive though</p>

<blockquote>
  <p>Notice: Undefined variable: uid in update_salary.php on line 18</p>
</blockquote>
