Jump to content

crashintome1019

New Members
  • Posts

    5
  • Joined

  • Last visited

crashintome1019's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for your help on my question ealier about my PHP shopping cart with the drop-down menu. You gave me this following code: <?php // define the print options (array key is the id/identifier) $print_options[1] = array('price'=>175.00,'name'=>"11x14 Canvas Wrap"); $print_options[2] = array('price'=>250.00,'name'=>"16x20 Canvas Wrap"); $print_options[3] = array('price'=>280.00,'name'=>"20x30 Canvas Wrap"); $print_options[4] = array('price'=>325.00,'name'=>"30x40 Canvas Wrap"); $print_options[5] = array('price'=>20.00,'name'=>"4x6 Print"); $print_options[6] = array('price'=>30.00,'name'=>"5x7 Print"); $print_options[7] = array('price'=>50.00,'name'=>"8x10 Print"); $print_options[8] = array('price'=>75.00,'name'=>"11x14 Print"); $print_options[9] = array('price'=>100.00,'name'=>"16x20 Print"); $print_options[10] = array('price'=>125.00,'name'=>"16x24 Print"); $print_options[11] = array('price'=>150.00,'name'=>"20x30 Print"); $print_options[12] = array('price'=>175.00,'name'=>"24x36 Print"); $print_options[13] = array('price'=>200.00,'name'=>"30x40 Print"); $print_options[14] = array('price'=>250.00,'name'=>"40x50 Print"); $print_options[15] = array('price'=>300.00,'name'=>"40x60 Print");?> <form action="cart.php" method="post"><select name="prints"><option value="">Select a print size</option> <?php foreach($print_options as $option_id=>$option){ echo "<option value='$option_id'>{$option['name']} - $".number_format($option['price'],2)."</option>\n";}?></select><input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /><input type="submit" name="button" id="button" value="Add Selected to Shopping Cart" /></form><br /> Which makes complete sense. What I am having trouble with now is getting my cart.php to display the selection. I was wondering if you might be able to help out with that code as well? I've spent the majority of the day today trying every different variation I could to get it to work, with zero results. The code I currently have on my cart.php page is as follows: foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while ($row = mysql_fetch_array($sql)) { $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; } $pricetotal = $price * $each_item['quantity']; $cartTotal = $pricetotal + $cartTotal; setlocale(LC_MONETARY, "en_US"); $pricetotal = money_format("%10.2n", $pricetotal); // Dynamic Checkout Btn Assembly $x = $i + 1; $pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"> <input type="hidden" name="amount_' . $x . '" value="' . $price . '"> <input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> '; // Create the product array variable $product_id_array .= "$item_id-".$each_item['quantity'].","; // Dynamic table row assembly $cartOutput .= "<tr>"; $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="100" height="67" border="1" /></td>'; $cartOutput .= '<td>' echo $option_name '</td>'; $cartOutput .= '<td>' echo $option_id '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /> <input name="adjustBtn' . $item_id . '" type="submit" value="change" /> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td>' . $pricetotal . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>'; $cartOutput .= '</tr>'; $i++; I just can't seem to figure out how to output the values from the product.php page. Thanks!
  2. Thanks! I'm still struggling with the cart.php but I'll keep working on it. You've been a great help!
  3. Any help that one can provide would be leaps and bounds past what I currently have. I would appreciate it so much, thank you!
  4. Hello, I'm sorry if I'm not posting this in the correct section; I appologize if I'm not. I'm new to this whole PHP thing, and I am currently building an e-commerce website based on Adam Khoury's video tutorial series on youtube. I'm at a wall here with what I'm trying to do. I've got a drop-box next to the images (products) so that customers can choose which size they will need (the prices will change as well). In the shopping cart page I've got a table with the "Product", "Product Description", "Unit Price", "Quantity", "Total Price" and "Remove" each in their perspective columns. When a customer chooses from the drop-down, I would like that then to send a dollar value to the "Unit Price" column of the cart page and I would also like it to list the size/type of print in the "Product Description" box. I'm not sure how to get it to generate two values like that, or if it's even possible. But here's what I have for code for the product selection page: <form action="cart.php" method="post"> <select name="prints"> <option value="">Select a print size</option> <option value="175.00" name="11x14 Canvas Wrap - $175.00" id="175" >11x14 Canvas Wrap - $175.00 </option> <option value="250.00" name="16x20 Canvas Wrap - $250.00" id="250" >16x20 Canvas Wrap - $250.00 </option> <option value="280.00" name="20x30 Canvas Wrap - $280.00" id="280" >20x30 Canvas Wrap - $280.00 </option> <option value="325.00" name="30x40 Canvas Wrap - $325.00" id="325" >30x40 Canvas Wrap - $325.00 </option> <option value="20.00" name="4x6 Print - $20.00" id="20" >4x6 Print - $20.00 </option> <option value="30.00" name="5x7 Print - $30.00" id="30" >5x7 Print - $30.00 </option> <option value="50.00" name="8x10 Print - $50.00" id="50" >8x10 Print - $50.00 </option> <option value="75.00" name="11x14 Print - $75.00" id="75" >11x14 Print - $75.00 </option> <option value="100.00" name="16x20 Print - $100.00" id="100" >16x20 Print - $100.00 </option> <option value="125.00" name="16x24 Print - $125.00" id="125" >16x24 Print - $125.00 </option> <option value="150.00" name="20x30 Print - $150.00" id="150" >20x30 Print - $150.00 </option> <option value="175.00" name="24x36 Print - $175.00" id="176" >24x36 Print - $175.00 </option> <option value="200.00" name="30x40 Print - $200.00" id="200" >30x40 Print - $200.00 </option> <option value="250.00" name="40x50 Print - $250.00" id="251" >40x50 Print - $250.00 </option> <option value="300.00" name="40x60 Print - $300.00" id="300" >40x60 Print - $300.00 </option> <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /> <input type="submit" name="button" id="button" value="Add Selected to Shopping Cart" /></form><br /> I know I will need to add another value in order to get it to generate another value on the "cart.php" page, but I'm just not sure how. My cart.php is an absolute mess which I will have to clean up as well. (PHP boggles my mind). Here's what the code looks like to re-generate the information into that table I was telling you about: <p><?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 4 (if user wants to remove an item from cart) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") { // Access the array and run code to remove that array index $key_to_remove = $_POST['index_to_remove']; if (count($_SESSION["cart_array"]) <= 1) { unset($_SESSION["cart_array"]); } else { unset($_SESSION["cart_array"]["$key_to_remove"]); sort($_SESSION["cart_array"]); } } ?> <?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 5 (render the cart for the user to view on the page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $cartOutput = ""; $cartTotal = ""; $pp_checkout_btn = ''; $product_id_array = ''; if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { $cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>"; } else { // Start PayPal Checkout Button $pp_checkout_btn .= '<form action="[url="https://www.paypal.com/cgi-bin/webscr"]https://www.paypal.com/cgi-bin/webscr[/url]" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.