Page 1 of 1

adding session

Posted: Mon Apr 30, 2007 5:08 am
by kpraman
I am trying to add session to shopping cart. This is the code i am using, it is not working. The values gets lost once i add another product.

Code: Select all

if (!isset($_SESSION['checkbox']) || !is_array($_SESSION['checkbox'])) 
		{ 
			$_SESSION['checkbox'] = array(); 
		} 
		$_SESSION['checkbox'][] = $_POST['checkbox'];
		$_SESSION['checkbox'];
		
		print_r($checkbox);
checkbox contains prodId's

Re: adding session

Posted: Mon Apr 30, 2007 6:41 am
by mentor
kpraman wrote:checkbox contains prodId's
Which variable you are talking about? $checkbox or $_POST['checkbox']?

Code: Select all

if (!isset($_SESSION['checkbox']) || !is_array($_SESSION['checkbox'])) 
{ 
	$_SESSION['checkbox'] = array(); 
} 
$_SESSION['checkbox'][] = $_POST['checkbox']; 
$_SESSION['checkbox']; // what is the need for this line?

print_r($checkbox);
Isn't it should be like

Code: Select all

print_r($_SESSION['checkbox']);

Posted: Mon Apr 30, 2007 8:37 am
by superdezign
Absolutely no idea what you are trying to accomplish here. Are you saving which checkboxes are checked for later usage...?

Posted: Mon Apr 30, 2007 11:43 am
by RobertGonzalez
You need to approach this differently.

Code: Select all

<?php
if (!empty($_POST['checkbox']))
{
    $_SESSION['checkbox'] = $_POST['checkbox'];
}
?>