Re: How to remove item from cart

From: Date: Mon, 24 Jun 2002 04:57:03 +0000
Subject: Re: How to remove item from cart
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-103533@lists.php.net to get a copy of this message
Hi Vicki: On Sun, Jun 23, 2002 at 09:30:39PM -0400, Vicki wrote: > I have a shopping cart where users have added a list of documents for > purchase. I want to allow users to remove documents from the cart before > checkout. There are no quantities involved-- this is a "yes I want > $docID" or "no I don't" situation. The whole process starts with the form. If that's not made correctly, you aren't going to get anywhere in your checkout. From your code, I have a hunch that's where your first problem lies. <form> <input type="checkbox" name="item[124]" checked /> <input type="checkbox" name="item[268]" checked /> </form> Now, the receiving script: if ( !empty($_POST['save']) ) { if ( empty($_POST['item']) OR !is_array($_POST['item']) ) { echo "HEY! You haven't selected any items!"; } else { while ( list($ID,) = each($_POST['item']) ) { $cart[$ID]; } } } This doesn't delete stuff from the cart. It just creates a new $cart array containing only the things the person wants. Note, I'm using empty() a lot to avoid "Warnings" in the event the variables aren't set at all. Also using the $_POST[] superglobal array, assuming you're using a version of PHP >= 4.1.0. Enjoy, --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

« previous php.general (#103533) next »