Hi i want the values which are selected should be stored in a session. here i have stored all the values which are available how to do it.......pls give me solution.............

<?php

	include('database.php');


 $stype=$_POST['category'];
if($stype=="service_category")
   { 
	 
	 $result = mysql_query("SELECT * FROM  service_category ");
	while($row = mysql_fetch_array($result))
		{
		?><input type="Checkbox" name="a[]" id="a[]"  value="servicec"><?echo $row['servicec'];
		echo "<br />";
		$a[$i]=$row['servicec'];
		$i++;
		$_SESSION['a1']=$a[i];
			//	echo  $_SESSION['a1'];

		}
		$_SESSION['a1']=$a; 
		

   }

Hi,

for this you do not need to store all the values in session.

while($row = mysql_fetch_array($result))
{
?><input type="Checkbox" name="a[]" id="a[]" value="<?=$row['servicec']?>"><?echo $row['servicec'];
echo "<br />";
$i++;
}

now when you will post this page then in next page you will get only those values that are selected then you can store those values in session.

You can test the following example.

<?
   if(isset($_POST["submit"]))
	{
		$aa = $_POST["a"];
		foreach($aa as $i)
		{
			echo $i." ";
		}		
		exit;
	}

?>

<form method=post action="">
<input type=checkbox name=a[] id=a[] value=1> 
<input type=checkbox name=a[] id=a[] value=2> 
<input type=checkbox name=a[] id=a[] value=3> 
<input type=checkbox name=a[] id=a[] value=4> 
<input type=checkbox name=a[] id=a[] value=5> 

<input type=submit name=submit value=submit>
</form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.