condirant Posted June 16, 2011 Share Posted June 16, 2011 I'm working on a script at: http://fadedroyalty.rmlddesigns.com I'm having an issue where if a user adds one small shirt to cart, and then another shirt on the same row of the same size, and then you try to remove one of those items from the cart, I get the error: "Warning: extract() [function.extract]: First argument should be an array in [....]functions.inc.php on line 35" Here's the function that contains the problem, I think: function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); //$contents = array(); global $contents; foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } $output[] = '<form action="cart.php?action=update" method="post" id="cart">'; $output[] = '<table>'; foreach ($contents as $id=>$qty) { if($_GET['size'] == 'none') { $sql = "SELECT * FROM products WHERE id = ".$id; } else { $sql = "SELECT * FROM products WHERE id = '".$id."'"; } $result = $db->query($sql); $row = $result->fetch(); extract($row); $output[] = '<tr>'; $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>'; $output[] = '<td>'.$itemname.'</td>'; $output[] = '<td>$'.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>$'.($price * $qty).'</td>'; $total += $price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; if($total <= 74) { $orig_total = $total; $total = $total+5.95; $output[] = '<p>Total: <strong>$'.$orig_total.'. With shipping($5.95): <strong>$'.$total.'</strong></p>'; } else { $output[] = '<p>Your order is over $75, so shipping is free. Grand total: <strong>$'.$total.'</strong></p>'; } $output[] = "<div><button type='submit'>Update cart</button><button type='button' onClick=\"window.location = 'checkoutp1.php'; \">Checkout</button></div>"; $output[] = "</form>"; $output[] = "<script> if(window.location != 'http://fadedroyalty.rmlddesigns.com/cart.php?action=update) { document.forms['cart'].submit(); } </script>"; } else { $output[] = "<p>You shopping cart is empty.</p>"; } return join('',$output); } Anybody that helps me solves this, I greatly appreciate your help, and if you want to become business partners I will pay you for work when I get it. Thanks anyone!! Quote Link to comment https://forums.phpfreaks.com/topic/239506-hello-internetz-help-needed-with-simple-custom-php-shopping-cart/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.