phpnj1 Posted March 11, 2010 Share Posted March 11, 2010 Hi, I'm working on a mock web store for a school project. I'm stuck trying to get my cart to display right. I've been following/editing a tutorial I found online but I keep getting this error: Warning: extract() expects parameter 1 to be array, boolean given in C:\xampp\htdocs\inc\functions.inc.php on line 29 here is the entire showCart function. any ideas what's causing this? Thanks in advance. function showCart() { global $db; $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); 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) { $sql = 'SELECT * FROM inventory WHERE productID = '.$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>'.$title.' by '.$author.'</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>'; $output[] = '<p>Grand total: <strong>$'.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } Link to comment https://forums.phpfreaks.com/topic/194923-help-displaying-cart-contents-in-a-web-store/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.