On one of my pages I need to add an element to an array each time a submit button is pressed. The array is saved as a session variable so the user can add another element. To see if I can get the idea to work, I have a simplified version of what I need. I have print statements to show me what is in the array each time the page is updated, but nothing prints. I would appreciate anyone looking at the following code and leading me in the right direction.
<?php
// Initialize a session. This call either creates
// a new session or re-establishes an existing one.
session_start( );
// If this is a new session, then the variable
// $count will not be registered and we initialize
if (!session_is_registered("counttest"))
{
$counttest = array();
session_register("counttest");
session_register("count");
session_register("value");
$SESSION['count'] = '1';
$SESSION['value'] = 'A';
$SESSION["counttest['$count']"] = $value;
}
else
{
$SESSION['count']++;
$SESSION['value']++;
$SESSION["counttest[$SESSION[count]"] = $SESSION['value'];
//asort($SESSION['counttest'];
print_r ($SESSION['counttest']);
foreach($_SESSION['counttest'] as $varname => $value)
print $count . "has a value of ".$value;
}
$sessionId = session_id( );
echo "$sessionId";
echo "<br>";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test Session</title>
</head>
<body>
<a href = "testsession.php"> Reload page </a>
</p>
</body>
</html>
Thanks.
Ivan Gepner
gepner@monmouth.edu