0

I'm trying to figure out why my PHP var does not update. I tried multiple solutions, not sure if i am doing something wrong, or this does just not work.

Any tips are appreciated.

<form method="post">
  <button type="submit" name="test"> 10  </button>
</form>

<?php
    if(!isset($_SESSION['money']))
    {
       $_SESSION['money'] = 100;
    }

    if(isset($_POST['test']))
    {
        $money = $_SESSION['money'];
        $money++;
        $_SESSION['money']= $money;
        echo $money;
    }
?>
0

2 Answers 2

3

You don't seems to have started the session. Make sure you've put the line session_start(); at the top of your php files

Sign up to request clarification or add additional context in comments.

3 Comments

Wow, beginners mistake ! Totally missed that, thanks alot!
No problem ;-) Could you please mark answer as solved ?
Will do, in 6 minutes. SO has a timer on the solved answer.
1

missing session and action

<?php session_start();  ?>
<form method="post" action="">
  <button type="submit" name="test"> 10  </button>
</form>

<?php
    if(!isset($_SESSION['money']))
    {
       $_SESSION['money'] = 100;
    }

    if(isset($_POST['test']))
    {
        $money = $_SESSION['money'];
        $money++;
        $_SESSION['money']= $money;
        echo $money;
    }
?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.