Re: More on removing item from cart

From: Date: Wed, 26 Jun 2002 03:49:30 +0000
Subject: Re: More on removing item from cart
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-103909@lists.php.net to get a copy of this message
Hey Vicki: On Tue, Jun 25, 2002 at 10:15:24PM -0400, Vicki wrote: > <th bgcolor=\"#cccccc\">Word Count</th></tr>"; bgcolors in table cells can lead to unreadable results. See http://www.analysisandsolutions.com/code/weberror.htm?ft=y ... snip ... > echo "<td width=5% align = left bgcolor=\"#f4f4ea\"> Your HTML is BAD BAD BAD. :) All attributes must be quoted. Just because some browsers let you slide on that doesn't make it right. So, that line, for example, should read: echo "<td width=\"5%\" align=\"left\" bgcolor=\"#f4f4ea\"> Fix all of your code accordingly. > <input type = checkbox name = \"$artID\" value = yes > checked></td>"; The "value=yes" is unnecessary. Since only checked boxes are sent, the existence of the variable itself is proof that it's true. More importantly, go back to the name I suggested: <input type=\"checkbox\" name=\"want[$artID]\" checked /></td>"; ... snip ... > > href=\"show_article.php?artID=".$artID."\">".$article["headline"]."</a> Put the array's key name in single quotes when you're not evaluating it. So, $article["headline"] is better done as $article['headline'] > echo "<td align = center>$article[numwords]</td>"; Hey, you didn't pop that array out. Again, when strings contain things you don't need to evaluate, put them in single quotes: echo '<td align="center">' . $article['numwords'] . '</td>'; ... snip .... > //relevant code from receiving page "show_cart.php" > > if($save) > { > foreach($cart as $artID => $value) I have a feeling the problem is right here. What's the structure of the $cart array? Does it contain a multidimensional array where the first key is the article ID and second key is the field name, kind of like this: $cart[1]['title'] = 'the bliss of success'; $cart[1]['wordlenth'] = 55; If that's the case, then > if(empty($value)) can be rewritten as: if ( empty($want[$artID]) ) If I'm guessing wrong, let me know. > unset($cart[$artID]); > else > $cart[$artID] = $$artID; What's the point of that line? Seems odd. 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 (#103909) next »