Update session variable?
Posted: Fri Dec 18, 2009 5:15 pm
I have done a few google searches trying to find out how i can update a session value without destroying and restarting all the sessions(not what i want), from google i mainly find javascript soloutions to changing session variables.
Here is segment of code in question:
As you can see when the DB is updated i also tried to update the session value of user_money. This has had no effect so i just came here to find the correct way to update a session value. Thanks 
Here is segment of code in question:
Code: Select all
// calculate the cost of the job
$total_cost = round(($_POST['amountworkers'] * $_POST['perperson']) * 1.05, 2);
$user_cost = $_SESSION['user_money'];
try {
if ($total_cost > $user_cost) {
throw new Exception("incorrect funds"); // does the user have the correct amount of money?
}
// if the user does have enough money process the update in DB
else{
$_SESSION['user_money'] = round($user_cost - $total_cost, 2); // not working
$sql = "UPDATE `users`
SET users.user_money = round($user_cost - $total_cost, 2)
WHERE users.id = '$_SESSION[user_id]'";
$result = mysql_query($sql)
or die('Invalid query: ' . $sql . ' - Error is ' . mysql_error());
}