unregister one (not all) session..

They have: 164 posts

Joined: Nov 2001

hi, i'm working on a shopping cart. i store the necesary field in session and pass it to user cart when user add the item to cart.

this is how i store my session:

<?php
if (isset($HTTP_POST_VARS['pid']['pid']))
    {
        if (
is_array($_SESSION['pid']))
        {
            if (!
in_array($HTTP_POST_VARS['pid']['pid'], $_SESSION['pid']))
            {
                               
$_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
            }   
        }else
        {
                       
$_SESSION['pid'][] = $HTTP_POST_VARS['pid']['pid'];
        }
    }
?>

this is the checkbox:

<?php
print \"<td width=5
?>
\n\";

?>

and this, when user check the checkbox and click delete:

<?php
for ($i=0; $i<count($cb); $i++)
        {
            unset(
$_SESSION['pid'][$cb[$i]] );
        }
?>

if i hv 2 or more records in my cart, when i check the first item to be deleted, it will delete all of them. anything wrong with my code?

pls !

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

try this:

<?php
foreach ($cb as $i) {
    unset(
$_SESSION['pid'][$i] );
}
?>

They have: 164 posts

Joined: Nov 2001

i got this error:

Quote:
Warning: Invalid argument supplied for foreach() in c:\inetpub\wwwroot\kbj\shop_cart\user_cart.php on line 144

and line 144 is :

<?php
foreach ($cb as $i) {
?>

He has: 1,016 posts

Joined: May 2002

joyce, how about I sponsor you with a little space/bandwidth on a real Linux server for development's sake? Email me..

Cheers..

They have: 164 posts

Joined: Nov 2001

hi zollet,

i normally worked on localhost first b4 i upload it to the server.

this is the session file(when i add 2 records into the cart):

Quote:
pid|a:2:{i:0;s:1:"4";i:1;s:1:"1";}

and this is the session file when i choose one of the record to delete:

Quote:
pid|a:1:{i:1;s:1:"1";}

but on my page, when choose one record to be deleted, it deletes all the records. so it shows an empty cart at my page.
i just dono why...

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

If the foreach is failing, then $cb is not an array.

They have: 164 posts

Joined: Nov 2001

my checkbox is like this:

<?php
print \"<td width=5
?>
\n\";

?>
it is an array wat..isn't it??

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I have 2 debug ideas...
1-inclose the cb[] in quotes
2-print $cb

<?php
// 1
print \"<td width=5
?>
\n\";

// 2
print_r($cb);

?>

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.