使用数组插入多行

时间:2017-11-06 10:30:46

标签: php mysql arrays

我有一组包含数组的行。我想在数据库中插入数据,但是当我插入它时,它会在数据库中插入最后一行的数据。

输入 Input

数据库输出 output in database

HTML

    <select class="price" name="orderedproduct[]" id="orderedproduct'+counter+'" row="'+counter+'">
    <option>Select Ordered Product</option>
    <option value="5">VITANKA</option>
    <option value="14">INCAPROT</option>
    <option value="15">METHOLIP</option>
    </select>

    <input type="text" name="productqty[]" id="productqty'+counter+'" class="gui-input txtQuantity" placeholder="Quantity" row="'+counter+'">

    <input type="text" name="orderedamount[]" id="orderedamount'+counter+'" class="gui-input orderamount" placeholder="Total Amount" row="'+counter+'">

<input type="submit" class="btn btn-primary" id="submit" name="submit" value="Submit Report">

PHP

$sql3="";
if($_POST['orderedproduct'])
{
//$productqty=$_POST['productqty'];
//var_dump($productqty);
                                            //$orderedamount=$_POST['orderedamount'];
//var_dump($orderedamount);
foreach($_POST['productqty'] as $productqty1)
{
$productqty=$productqty1;   
}

foreach($_POST['orderedamount'] as $ordredamount1)
{
$orderedamount= $ordredamount1; 
}

foreach($_POST['orderedproduct'] as $orderedproduct)
{

$sql3.="( (SELECT MAX(D_C_R.DCR_ID) FROM D_C_R),$orderedproduct,$productqty,$orderedamount),";

}
//echo implode("",$productqty);
$sql3="INSERT INTO ORDER_TABLE(ORDER_TABLE.DCR, ORDER_TABLE.PRODUCT, ORDER_TABLE.QTY, ORDER_TABLE.AMOUNT)   VALUES".trim($sql3,',');

$res3=mysql_query($sql3) or die(mysql_error());
}

0 个答案:

没有答案