hello i have problem with the following code that is on the head of every page:
session_start();
if (!isset($_SESSION['a'])){
...create the session from some variables...
$_SESSION['a'] = $var;
$var = $_SESSION['a'];
}else{
$var = $_SESSION['a'];
$what = "some text";
if (isset($_POST['one']) ){
$var = "new input";
$_SESSION['a'] = $var;
echo "one was posted";
}
if (isset($_POST['two']) ){
$var = "new input";
$_SESSION['a'] = $var;
echo "two was posted";
}
}
the form to post is placed in the footer:
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="one" name="one"/><div>set one</div>
</form>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="two" name="two"/><div>set two</div>
</form>
something seems to be wrong in the logic behind the code above. when calling the page, and sending post issue, it will not echo and not change the session to the new value.
so if there is someone who could help me out i really would appreciate.
thanks alot.
UPDATE:
okay, the code works completely up to the “else” part:
else{
$var = $_SESSION['a'];
if (isset($_POST["one"]) ){
echo "post one was send";
}
if (isset($_POST["two"]) ){
echo "post en was send";
}
echo "session already exists.";
}
this part only shows the echo: session already exists. the whole post phrase does not work.
the footer will be embedded depending from some variables. so the whole content in html will be echoed:
echo '...
<ul class="drop_down">
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="one" name="one value="one"/><div>set one</div>
</form>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="two" name="two" value="two"><div>set two</div>
</form>
</ul>
...';
Change Your Form
value Need to be sent..
Edit#1:
In my system this is working fine..
Edit#2
Try this again…
Here
sessionis printing correctly