2017-11-19 4 views
0

1つのテーブルで複数の製品名をアップロードするにはどうすればよいですか?
(ここでは私の現在のSQLがマルチ単一ではないに取り組んでそれを更新している):セッションカートで複数sqlをアップロード

$query = "INSERT INTO order_details(product_name) VALUES('$product_name')"; 

そして、これはセッションを使用して私の例入力フォームカート(すでにあまりにも長い間、それだって、いくつかのラインをカット)である:

 <?php 
 
    \t if(isset($_SESSION["cart_products"])) //check session var 
 
     { 
 
    \t \t $total = 0; //set initial total value 
 
    \t \t $b = 0; //var for zebra stripe table 
 
    \t \t foreach ($_SESSION["cart_products"] as $cart_itm) 
 
      { 
 
    \t \t \t //set variables to use in content below 
 
    \t \t \t $product_name = $cart_itm["product_name"]; 
 
    \t \t \t $product_qty = $cart_itm["product_qty"]; 
 
    \t \t \t $product_price = $cart_itm["product_price"]; 
 
    \t \t \t $product_code = $cart_itm["product_code"]; 
 
    \t \t \t $product_color = $cart_itm["product_color"]; 
 
    \t \t \t $subtotal = ($product_price * $product_qty); //calculate Price x Qty 
 
    \t \t \t 
 
    \t \t  \t $bg_color = ($b++%2==1) ? 'odd' : 'even'; //class for zebra stripe 
 
    echo '<td width="5%"><input type="checkbox" class="inp_check " name="remove_code[]" value="'.$product_code.'" /> 
 
     </section> 
 
    </td>'; 
 
    echo '<td width="40%" align="left"><input type="hidden" name="product_name" value="'.$product_name.'">'.$product_name.'</td>'; 
 
    echo '<td width="5%" align="center"><input type="number" size="2" class="ip_remove" maxlength="2" name="product_qty['.$product_code.']" value="'.$product_qty.'" /> Unit</td>'
私がやりたいことは、人々がボタンをクリックしたときに提出し、それは単一の更新

と同じようにSQLをアップロードしなければならないです

id order_id product_name  product_price 
    1  14   iphone 7  USD700 
    1  14   iphone 7s  USD700  
    1  14   iphone 5  USD700 

    2  15   iphone 7  USD700 
    2  15   iphone 7s  USD700 
    2  15   iphone 5  USD700 

0またはこの例写真SQLで enter image description here

答えて

0

values複数のエントリを受け入れることができ、例:彼らの購入の場合

INSERT INTO order_details(product_name) 
VALUES 
    ('product1'), 
    ('producut2'), 
    ('product3'); 
+0

はそれが動作しない以上、その後3 –

関連する問題