ethan6 Posted February 13, 2010 Share Posted February 13, 2010 Hello, I have a simple shopping cart in php and I have it set that when the user wants, they can click checkout and it brings them to paypal to pay. Unfortunately, I can't seem to get all the variables to output in the "items" line, i can only get the last item in the cart (I think it's like in an array?) Here's the code of the function showCart() that has the button to click on to go to paypal at the bottom: 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 parts 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>'.$part.'</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><br>'; $output[] = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">'; $output[] = '<input type="hidden" name="cmd" value="_xclick">'; $output[] = '<input type="hidden" name="business" value="[email protected]">'; $output[] = '<input type="hidden" name="item_name" value="'.$part.'">'; $output[] = '<input type="hidden" name="item_number" value="'.$id.'">'; $output[] = '<input type="hidden" name="amount" value="'.$total.'">'; $output[] = '<input type="hidden" name="shipping" value="2.99">'; $output[] = '<input type="hidden" name="no_shipping" value="2">'; $output[] = '<input type="hidden" name="return" value="http://itronicsrepair.com/thankyou_order.php">'; $output[] = '<input type="hidden" name="cancel_return" value="http://itronicsrepair.com/cancel_order.php">'; $output[] = '<input type="hidden" name="currency_code" value="USD">'; $output[] = '<input type="hidden" name="tax" value="0.00">'; $output[] = '<input type="hidden" name="lc" value="US">'; $output[] = '<input type="hidden" name="bn" value="PP-BuyNowBF">'; $output[] = '<input type="image" src="http://itronicsrepair.com/img/checkout.jpg" border="0" name="submit" alt="Make payments with PayPal - it is fast, free and secure!">'; $output[] = '<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> It is this line above where I want to output every part id#, not just the last one in the list: $output[] = '<input type="hidden" name="item_name" value="'.$part.'">'; Any thoughts? thanks. oh if you want to view the cart, it is at http://itronicsrepiar.com/parts.php .. put something in the cart and then it brings you to http://itronicsrepair.com/cart.php thanks. Link to comment https://forums.phpfreaks.com/topic/191934-shopping-cart-in-php-how-to-output-all-variables-array/ Share on other sites More sharing options...
ethan6 Posted February 13, 2010 Author Share Posted February 13, 2010 sorry that one link didn't work.. you can view the parts/cart here: http://itronicsrepair.com/parts.php http://itronicsrepair.com/cart.php Link to comment https://forums.phpfreaks.com/topic/191934-shopping-cart-in-php-how-to-output-all-variables-array/#findComment-1011643 Share on other sites More sharing options...
ethan6 Posted February 13, 2010 Author Share Posted February 13, 2010 anyone? Link to comment https://forums.phpfreaks.com/topic/191934-shopping-cart-in-php-how-to-output-all-variables-array/#findComment-1011786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.