Jump to content

[SOLVED] How do I update $_SESSION data.


Alecdude

Recommended Posts

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

   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.

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.