Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'view cart shopping cart'.



More search options

  • 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. Hello I keep getting "Your cart is currently empty." regardless of what is added to the cart. Here are two scripts: add_cart.php and view_cart.php view_cart.php <?php # Script 19.10 - view_cart.php // This page displays the contents of the shopping cart. // This page also lets the user update the contents of the cart. // Set the page title and include the HTML header: $page_title = 'View Your Shopping Cart'; include ('header.html'); // 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: include_once('common.php'); // Connect to the database. $q = "SELECT print_id, CONCAT_WS(' ', first_name, middle_name, last_name) AS artist, print_name FROM artists, prints WHERE artists.artist_id = prints.artist_id AND prints.print_id IN ("; foreach ($_SESSION['cart'] as $pid => $value) { $q .= $pid . ','; } $q = substr($q, 0, -1) . ') ORDER BY artists.last_name ASC'; $r = mysqli_query ($con, $q); // Create a form and a table: echo '<form action="view_cart.php" method="post"> <table border="0" width="90%" cellspacing="3" cellpadding="3" align="center"> <tr> <td align="left" width="30%"><b>Artist</b></td> <td align="left" width="30%"><b>Print Name</b></td> <td align="right" width="10%"><b>Price</b></td> <td align="center" width="10%"><b>Qty</b></td> <td align="right" width="10%"><b>Total Price</b></td> </tr> '; // Print each item... $total = 0; // Total cost of the order. $count=1; while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) { // Calculate the total and sub-totals. $subtotal = $_SESSION['cart'][$row['print_id']]['quantity'] * $_SESSION['cart'][$row['print_id']]['price']; $total += $subtotal; // Print the row: echo "\t<tr> <td align=\"left\">{$row['artist']}</td> <td align=\"left\">{$row['print_name']}</td> <td align=\"right\">£{$_SESSION['cart'][$row['print_id']]['price']}</td> <td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['print_id']}]\" value=\"{$_SESSION['cart'][$row['print_id']]['quantity']}\" /></td> <td align=\"right\">$" . number_format ($subtotal, 2) . "</td> </tr>\n"; $string_of_item_names = $string_of_item_names.' <input type="hidden" name="item_name_'.$count.'" Value="'.$row['print_name'].'" >'; # build item name string of all items in the basket $string_of_item_amounts = $string_of_item_amounts.' <input type="hidden" name="amount_'.$count.'" Value="'. number_format ($subtotal, 2).'" >'; # build string of prices for items in basket # use count as a reference to match names with prices in paypal $count++; } // End of the WHILE loop. mysqli_close($con); // Close the database connection. $checkout_button = ('<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <!-- Identify your business so that you can collect the payments. HELP: https://www.paypal.com/us/cgi-bin/webscr?cmd=_pdn_xclick_techview_outside https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/#id08A6HF00TZS We use cart becuase we have our own (third party which is us) --> <input type="hidden" name="business" value="mystore@gmail.com"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <!--- this is where the user comes back to after they finished making the payment ---> <input type="hidden" name="notify_url" Value="http://www.ecom/thankyou.php" /> <!-- Specify details about the item that buyers will purchase. --> '.$string_of_item_names.' '.$string_of_item_amounts.' <input type="hidden" name="currency_code" value="GBP"> <!-- Display the payment button. --> <input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online"> <img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" > </form>'); // Print the total, close the table, and the form: echo '<tr> <td colspan="4" align="right"><b>Total:</b></td> <td 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 />'.$checkout_button.'</p>'; } else { echo '<p>Your cart is currently empty.</p>'; } include ('footer.html'); ?> add_cart.php <?php # Script 19.9 - add_cart.php // This page adds prints to the shopping cart. // Set the page title and include the HTML header: $page_title = 'Add to Cart'; include ('header.html'); if (isset ($_GET['pid']) && filter_var($_GET['pid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) { // Check for a print ID. $pid = $_GET['pid']; // Check if the cart already contains one of these prints; // If so, increment the quantity: if (isset($_SESSION['cart'][$pid])) { $_SESSION['cart'][$pid]['quantity']++; // Add another. // Display a message: echo '<p>Another copy of the print has been added to your shopping cart.</p>'; } else { // New product to the cart. // Get the print's price from the database: include_once('common.php'); // Connect to the database. $q = "SELECT price FROM prints WHERE print_id=$pid"; $r = mysqli_query ($con, $q); if (mysqli_num_rows($r) == 1) { // Valid print ID. // Fetch the information. list($price) = mysqli_fetch_array ($r, MYSQLI_NUM); // Add to the cart: $_SESSION['cart'][$pid] = array ('quantity' => 1, 'price' => $price); // Display a message: echo '<p>The print has been added to your shopping cart.</p>'; } else { // Not a valid print ID. echo '<div align="center">This page has been accessed in error!</div>'; } mysqli_close($con); } // End of isset($_SESSION['cart'][$pid] conditional. } else { // No print ID. echo '<div align="center">This page has been accessed in error!</div>'; } include ('footer.html'); ?> Thanks
×
×
  • Create New...