Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.