I’ve got a problem. I’m sure I’m being really stupid but I can’t seem to be able to rertive a $_SESSION variable.
I run through the code three times using a variable called $setup which I post each time as reset. The first time I go through the code, $setup has no value. The second time, it has the value of 1 and a SESSION variable called value 1 gets set from a POST. The third time, setup has the value of 2. I set a SESSION variable to the value of another POST but the orignal SESSION variable seems to have disappear according to using print_r to find out what SESSIONS are set.
<?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'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>
Program
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="author" content="Richard Derek Young"/>
</head>
<body>
<h1>
Program
</h1>
<p>
Use this program to create it.
</p>
<?php
if ($setup==0)
{
?>
<p>
<form method="post" name="world" action="program.php">
Enter value 1. <br/>
<input type="text" name="value1"/>
<?php
$setup++;
?>
<input type="hidden" name="reset" value="<?=$setup;?>"/>
<input type="submit" value="Next"/>
</form>
</p>
<?php
}
elseif ($setup==1)
{
$setup++;
?>
<form method="post" name="description" action="program.php">
<input type="hidden" name="reset" value="<?=$setup;?>"/>
<p>
<input type="radio" name="value2" value="1" onclick="javascript:document.description.submit()"/> Option 1 <?=$value1;?>.
</p>
<p>0
<input type="radio" name="value2" value="2" onclick="javascript:document.description.submit()"/> Option 2 <?=$value1;?>
</p>
<p>
<input type="radio" name="value2" value="3" onclick="javascript:document.description.submit()"/> Option 3 <?=$value1;?>.
</p>
<p>
<input type="radio" name="value2" value="4" onclick="javascript:document.description.submit()"/> Option 4 <?=$value1;?>.
</p>
<p>
<input type="radio" name="value2" value="5" onclick="javascript:document.description.submit()"/> Option 5 <?=$value1;?>.
</p>
<p>
<input type="radio" name="value2" value="6" onclick="javascript:document.description.submit()"/> Option 6 <?=$value1;?>.
</p>
<p>
<input type="radio" name="value2" value="7" onclick="javascript:document.description.submit()"/> Option 7 <?=$value1;?>.
</p>
</form>
<?php
}
elseif ($setup==2)
{
$setup++;
echo $value2 . " " . $value1 . ".";
?>
<p>
More Stuff.
</p>
<?php
}
?>
<p>
<button onclick="<? session_destroy();?>window.location.href = 'program.php';">Reset</button>
</p>
</body>
</html>
It’s on line 90 that I only get value2 echoed.