Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to insert ordering data from multidimensional array
    primarykey
    data
    text
    <pre><code>&lt;?php ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Section 5 (render the cart for the user to view on the page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $cartOutput = ""; $cartTotal = ""; $pp_checkout_btn = ''; $checkout_btn = ''; $product_id_array = ''; if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) &lt; 1) { $cartOutput = "&lt;h2 align='center'&gt;Your shopping cart is empty&lt;/h2&gt;"; } else { // Start PayPal Checkout Button $pp_checkout_btn .= '&lt;form action="http://chenlikpharmacy.freeserver.me/order_list.php" method="post"&gt; &lt;input type="hidden" name="cartOutput" id="cartOutput" value = "&lt;?php echo $cartOutput; ?&gt; '; // Start the For Each loop $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sqlCommand = "SELECT * FROM products WHERE id='$item_id' LIMIT 1"; $sql = mysqli_query($myConnection,$sqlCommand); while ($row = mysqli_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, "ms_MY"); $pricetotal = money_format("%10.2n", $pricetotal); // Dynamic Checkout Btn Assembly $x = $i + 1; $pp_checkout_btn .= '&lt;input type="hidden" name="item_name[]" value="' . $product_name . '"&gt; &lt;input type="hidden" name="amount[]" value="' . $price . '"&gt; &lt;input type="hidden" name="quantity[]" value="' . $each_item['quantity'] . '"&gt; '; // Create the product array variable $product_id_array .= "$item_id-".$each_item['quantity'].","; // Dynamic table row assembly $cartOutput .= "&lt;tr&gt;"; $cartOutput .= '&lt;td&gt;&lt;a href="product.php?id=' . $item_id . '"&gt;' . $product_name . '&lt;/a&gt;&lt;br /&gt;&lt;img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /&gt;&lt;/td&gt;'; $cartOutput .= '&lt;td&gt;' . $details . '&lt;/td&gt;'; $cartOutput .= '&lt;td&gt;RM ' . $price . '&lt;/td&gt;'; $cartOutput .= '&lt;td&gt;&lt;form action="cart.php" method="post"&gt; &lt;input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /&gt; &lt;input name="adjustBtn' . $item_id . '" type="submit" value="change" /&gt; &lt;input name="item_to_adjust" type="hidden" value="' . $item_id . '" /&gt; &lt;/form&gt;&lt;/td&gt;'; //$cartOutput .= '&lt;td&gt;' . $each_item['quantity'] . '&lt;/td&gt;'; $cartOutput .= '&lt;td&gt;' . $pricetotal . '&lt;/td&gt;'; $cartOutput .= '&lt;td&gt;&lt;form action="cart.php" method="post"&gt;&lt;input name="deleteBtn' . $item_id . '" type="submit" value="X" /&gt;&lt;input name="index_to_remove" type="hidden" value="' . $i . '" /&gt;&lt;/form&gt;&lt;/td&gt;'; $cartOutput .= '&lt;/tr&gt;'; $i++; } setlocale(LC_MONETARY, "ms_MY"); $cartTotal = money_format("%10.2n", $cartTotal); $cartTotal = "&lt;div style='font-size:18px; margin-top:12px;' align='right'&gt;Cart Total : ".$cartTotal." MYR&lt;/div&gt;"; // Finish the Paypal Checkout Btn $pp_checkout_btn .= '&lt;input type="hidden" name="custom" value="' . $product_id_array . '"&gt; &lt;input type="submit" type="button" name="submit"&gt; &lt;/form&gt;'; } ?&gt; </code></pre> <p>The above is the source code I learnt online to create a multidimensional array and submit to paypal for processing. Now I try to avoid paypal and wanna to insert the data submitted to my new database 'orders'. I created row (id (primary,auto increment),product_name,price,quantity,date_added) for this purpose but I failed to insert the data into it....</p> <p>my attempt as below </p> <pre><code>&lt;?php // This file is www.developphp.com curriculum material // Written by Adam Khoury January 01, 2011 // http://www.youtube.com/view_play_list?p=442E340A42191003 session_start(); // Start session first thing in script // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); // Connect to the MySQL database include "storescripts/connect_to_mysqli.php"; ?&gt; &lt;?php  // Parse the form data and add inventory item to the system if (isset($_POST['cartOutput'])) { $product_name=mysqli_real_escape_string($myConnection,$_POST[' . $product_name . ']); $price=mysqli_real_escape_string($myConnection,$_POST[' . $price . ']); $quantity=mysqli_real_escape_string($myConnection,$_POST[$each_item['quantity']]); $date = date('d/m/Y', time()); $sqlCommand = ""INSERT INTO orders (product_name, price, quantity, date_added) VALUES('" . $_POST[$product_name] . "','" . $_POST[$price] . "','" . $_POST[$each_item['quantity']] . "', now())";     $sql = mysqli_query($myConnection,$sqlCommand) or die (mysqli_error()); $stmt = $mysqli-&gt;prepare($sql); $countArray = count($_SESSION["cart_array"); for ($i = 0; $i &lt; $countArray; $i++) { $stmt-&gt;bind_param('ssd', $array[$product_name][$i], $array[$price][$i], $array[$each_item['quantity']][$i],$array[$date][$i]); $stmt-&gt;execute(); } echo $sql   ; exit(); } ?&gt; </code></pre> <p>HELP~~~ I need to know what shall I put in if (isset($_POST['cartOutput'])) { in order to retrieve the date...i am really a beginner. I need some magic......</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload