Alecdude Posted December 10, 2008 Share Posted December 10, 2008 So, I have this script, and it is fully functional, but it doesn't update the session variables (Money stays at 15 whilst on the server it is 0, the badge1 is 1 on the server but 0 on the account). I need to be able to update the session variables so that it CHANGES them right away. Here is the buying code, if needed: if ($_POST['Submit']=='Buy'){ if ($_SESSION['Money'] > 14){ $sql = "UPDATE users SET Money=Money-15 WHERE id=".$_SESSION['user_id'].""; $sql2 = "UPDATE users SET badge1=1 where id=".$_SESSION['user_id'].""; $result = mysql_query($sql) or die (mysql_error()); $result2 = mysql_query($sql2) or die (mysql_error()); echo "<h3>You have received your badge!</h3><br><a href=myaccount.php>Click here to go to your account</a>"; } else { die ("<h3>You either own this badge or do not have enough ARO$.</h3><br><p>Please click the back button to go back a page.</p>"); } } Link to comment https://forums.phpfreaks.com/topic/136426-solved-how-do-i-update-_session-data/ Share on other sites More sharing options...
flyhoney Posted December 10, 2008 Share Posted December 10, 2008 $_SESSION['money'] = $newValue; Link to comment https://forums.phpfreaks.com/topic/136426-solved-how-do-i-update-_session-data/#findComment-711994 Share on other sites More sharing options...
premiso Posted December 10, 2008 Share Posted December 10, 2008 if ($_SESSION['Money'] > 14){ $sql = "UPDATE users SET Money=Money-15 WHERE id=".$_SESSION['user_id'].""; $sql2 = "UPDATE users SET badge1=1 where id=".$_SESSION['user_id'].""; $result = mysql_query($sql) or die (mysql_error()); $result2 = mysql_query($sql2) or die (mysql_error()); // now set session variables $_SESSION['Money'] = $_SESSION['Money'] - 15; $_SESSION['badge'] = 1; You are only updating the database. Link to comment https://forums.phpfreaks.com/topic/136426-solved-how-do-i-update-_session-data/#findComment-711996 Share on other sites More sharing options...
Alecdude Posted December 10, 2008 Author Share Posted December 10, 2008 Thank you, premiso! That worked! Link to comment https://forums.phpfreaks.com/topic/136426-solved-how-do-i-update-_session-data/#findComment-711999 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.