php - Storing and retrieving $_SESSION variables -
i've got problem. i'm sure i'm being stupid can't seem able rertive $_session variable. run throught code variable called $setup post each time reset. each time run through code increment $setup starts off no value has value 1 , then value 2. when it's one, set session posted value. next time when it's two, session doesn't seem have value.
this code when page loaded:
<?php session_start(); $setup=$_post['reset']; if ($setup==null) { $setup=0; } elseif ($setup==1) { $_session['value1']=$_post['value1']; $value1=$_session['value1']; } elseif ($setup==2) { $value1=$_session['value1']; $_session['value2']=$_post['value2']; $value2=$_session['value2']; } ?>
when setup 1 can print out value1 when setup 2 use code
echo $value2 . " " . $value1 . ".";
all value2 followed dot. doing wrong here?
in part of code :
elseif ($setup==2) { $value1=$_session['value1'];//here $_session['value2']=$_post['value2']; $value2=$_session['value2']; }
$_session['value1']
empty $value1
empty , instead of suggest code:
elseif ($setup==2) { if(isset($_session['value1']) $value1=$_session['value1']; else $value1='some value test'; $value2=$_session['value2']; }
also:
echo $value2 . " " . $value1 ".";
should :
echo $value2 . " " . $value1 . ".";//if want dot in end
or :
echo $value2 . " " . $value1 ;//without dot int end of line
Comments
Post a Comment