I can’t update my session value
this is the code
<CENTER>
<?PHP
session_start();
$_SESSION['value'] = 15;
if(isset($_POST['submit'])){
$plus = 10;
$_SESSION['value'] = ($_SESSION['value'] + $plus);
}
echo "<FORM METHOD=post ACTION=\"?page=try&". time(). "\" NAME=try>\n";
echo "<br>";
echo "Your value :" .$_SESSION['value'];
echo "<INPUT TYPE=submit NAME=submit VALUE=\"Submit\"></FORM>";
?>
</CENTER>
the problem is everytime I click that button, it always give me the same result.
that $_SESSION['value'] is always 15 and it never changes
so how to update the session value ? so I will get $_SESSION['value'] become 35 (the past result is 25 ) when I click the button again
thanks
you explicitly set the session value to 15, and then add 10 to it. It should never reach 35. try removing the assignment to 15 (or better yet, adding an
if(!isset($_SESSION['value']))check before it) and then try againYou should also take John Conde’s advice and make sure that you start the PHP session before sending any output. Please read the manual