unregister one (not all) session..
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
?>?>
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 posted this at 05:42 — 29th August 2002.
He has: 4,048 posts
Joined: Aug 2000
try this:
<?phpforeach ($cb as $i) {
unset( $_SESSION['pid'][$i] );
}
?>
joyce posted this at 08:41 — 29th August 2002.
They have: 164 posts
Joined: Nov 2001
i got this error:
and line 144 is :
<?phpforeach ($cb as $i) {
?>
zollet posted this at 12:11 — 29th August 2002.
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..
joyce posted this at 02:07 — 30th August 2002.
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):
and this is the session file when i choose one of the record to delete:
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 posted this at 02:25 — 30th August 2002.
He has: 4,048 posts
Joined: Aug 2000
If the foreach is failing, then $cb is not an array.
joyce posted this at 03:06 — 30th August 2002.
They have: 164 posts
Joined: Nov 2001
my checkbox is like this:
<?phpprint \"<td width=5
?>
?>
it is an array wat..isn't it??
Mark Hensler posted this at 05:20 — 30th August 2002.
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
?>
// 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.