session value not update

hi,
This is the code

[code]<?PHP
session_start();

$_SESSION[‘cash’] = 15000;

if(isset($_POST['play'])){
$win = 2 * 5 * 1000;
$lose = 15 * 1000;
$_SESSION['cash'] = ($_SESSION['cash']  + $win) - $lose;

}

echo “<FORM METHOD=post ACTION=“try1.php” NAME=try>\n”;
echo “
”;
echo “You have cash :” .$_SESSION[‘cash’]. "  ";
echo “<INPUT TYPE=submit NAME=play VALUE=“Play”>”;
?>

[/code]

I want everytime I click that play button will make that $_SESSION[‘cash’] value keep updating
how to make that ?

Well, you code works as is. But, I doubt it does anything for you.

First, in your code you set the session value of “cash” to 1500 EVERY time you run the script.
So, it does exactly what you programmed it to do. (As all computer do, they follow what you tell them!)
But, I doubt that is what you want it to do.

So, first, I doubt you showed us all of your code. You must think of this in a step-by-step order…

If you set the value to 1500 and then do something with the variable and then call the routine again,
it will just start over again at 1500 and then do something, etc…

So, you have to add a variable that tells your code that the original session variable has been set.
Or, you can create one starting PHP file that configs everything and the create a second file that does
the calculations. Any way you do this, you can not call a routine that starts off by setting the variable.
It will do this every time it is called.

Hope that made sense… Let us know when you get stuck…

Sponsor our Newsletter | Privacy Policy | Terms of Service