Problem with setting an array as session variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sivota
Forum Newbie
Posts: 1
Joined: Fri Oct 13, 2006 7:35 am

Problem with setting an array as session variable

Post by sivota »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi everyone,
    I have created two drop down lists in drop_list.php.When the user makes his choices
the page is refreshed in order to have the user the ability to choose more than once.
The problem is that after the refresh, in the page is printed only his current choice and 
not the previous.I think that the problem is when i set an array, that keeps all the elementes 
that have been chosen, as session variable.There must be something wrong in that point.
    You can see the page here:[url]http://195.251.195.102/aaa/drop_list.php[/url]
  
Here is the code of drop_list.php:

Code: Select all

<?php
error_reporting(E_ERROR);
session_start();

$category=array();
$subcategory=array();

//This variable increaseas every time that the page is refreshed
$counter=$_GET['counter'];

$category[$counter]=$_GET['cat'];
$subcategory[$counter]=$_GET['subcat'];

$_SESSION['category']=$category;
$_SESSION['subcategory']=$subcategory;

?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Categories and subcategories</title>
<script language="javascript" src="list.js"></script>
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000" onload="fillCategory1(),fillCategory2(),fillCategory3();">

<FORM name="drop_list" action="process.php" method="POST" >

<? 
$hidden=0+$counter;
echo "<input type=hidden name='counter' value=".$hidden.">"; 

if(strlen($_GET['cat'])>0)
{
for($i=1; $i<=$counter; $i++)
{
  echo "<input type=checkbox name='check".$i."' checked>&nbsp;&nbsp;".
       $_SESSION['category'][$i]."&nbsp;&nbsp;&nbsp;".$_SESSION['subcategory'][$i]."<BR><BR>";
   
}
}	

?>
<BR>		
<SELECT  NAME="Category1" onChange="SelectSubCat1();" >
<Option value="">Category</option>
</SELECT>&nbsp;
<SELECT id="SubCat1" NAME="SubCat1" onChange="reload(drop_list)">
<Option value="">SubCat</option>
</SELECT>&nbsp;

<br>
<input name="submit" type=submit value='Submit'>
</form>
</body>
</html>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Post Reply