Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'view_cart.php'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. This is an adaptation of the view_cart.php script in ch 19. It had worked previously until I changed servers/web hosting. It may be coincidental, however, when changing cart quantity to zero, it will either throw an error (undefined total variable) or add additional products to cart which were previously deleted in the same session. All other functions work propertly, including "add to cart" and "checkout" when quantities are not changed to zero. Any suggestions would be greatly appreciated. <div class="generalarticle"> <?php // add_cart.php $cart = $_SESSION['cart']; // Check if the form has been submitted (to update the cart): if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Change any quantities: foreach ($_POST['qty'] as $k => $v) { // Must be integers! $pid = (int) $k; $qty = (int) $v; if ( $qty == 0 ) { // Delete. unset ($_SESSION['cart'][$pid]); } elseif ( $qty > 0 ) { // Change quantity. $_SESSION['cart'][$pid]['quantity'] = $qty; } } // End of FOREACH. } // End of SUBMITTED IF. // Display the cart if it's not empty... if (!empty($_SESSION['cart'])) { // Retrieve all of the information for the prints in the cart: require ('../mysqli_connect.php'); // Connect to the database. $q = "SELECT * FROM products WHERE productID IN ("; foreach ($_SESSION['cart'] as $pid => $value) { $q .= $pid . ','; } $q = substr($q, 0, -1) . ') ORDER BY productName ASC'; $r = mysqli_query ($dbc, $q); // Create a form and a table: echo '<form action="https://www.mysite.net/view-cart/" method="post"> <fieldset class="checkout"> <legend class="checkout">My Shopping Cart</legend> <table border="0" width="90%" cellspacing="3" cellpadding="3" align="center"> <tr class="checkout" > <td class="checkout" align="left" width="30%"><b>Item Name</b></td> <td class="checkout" align="right" width="10%"><b>Price</b></td> <td class="checkout" align="right" width="10%"><b>Shipping</b></td> <td class="checkout" align="center" width="10%"><b>Qty</b></td> <td class="checkout" align="right" width="10%"><b>Total Price</b></td> </tr> '; // Print each item... $total = 0; // Total cost of the order. while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) { // Calculate the total and sub-totals. $subtotal = (($_SESSION['cart'][$row['productID']]['quantity'] * $_SESSION['cart'][$row['productID']]['price']) + ($_SESSION['cart'][$row['productID']]['quantity'] * $_SESSION['cart'][$row['productID']]['shipping'])); $total += $subtotal; // Print the row: echo "\t<tr class=\"checkout\"> <td class=\"checkout\" align=\"left\">{$row['productName']}</td> <td class=\"checkout\" align=\"right\">\${$_SESSION['cart'][$row['productID']]['price']}</td> <td class=\"checkout\" align=\"right\">\${$_SESSION['cart'][$row['productID']]['shipping']}</td> <td class=\"checkout\" align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['productID']}]\" value=\"{$_SESSION['cart'][$row['productID']]['quantity']}\" /></td> <td class=\"checkout\" align=\"right\">$" . number_format ($subtotal, 2) . "</td> </tr>\n"; } // End of the WHILE loop. mysqli_close($dbc); // Close the database connection. // Print the total, close the table, and the form: echo '<tr> <td class="checkout" colspan="4" align="right"><b>Total:</b></td> <td class="checkout" align="right">$' . number_format ($total, 2) . '</td> </tr> </table> <div align="center"><input type="submit" name="submit" value="Update My Cart" /></div> </form> <p align="center">Enter a quantity of 0 to remove an item. <br /><br /><a href="https://www.mysite.net/checkout/">Checkout</a> or <a href="https://www.mysite.net/real-estate-advertisement-packages/">Continue Shopping</a>.</p></fieldset>'; } else { echo '<p>Your cart is currently empty.</p>'; } $_SESSION['total'] = $total; // carry total to checkout $_SESSION['cart'] = $cart; // carry total to checkout ?> </div> <div class="sidebar"></div> <div class="spacer"></div> </div></div>
×
×
  • Create New...