简体   繁体   English

如何在数据库+ PHP的每一行中插入多个数组

[英]How to Insert Multiple Array into Each Row in Database+php

You may refer my code here . 您可以在这里参考我的代码

I'm creating an invoice and doing testing on my php . 我正在创建发票并在php上进行测试。
From the code given above, my data will be like this: 从上面给出的代码中,我的数据将如下所示:

Assuming id_invoice will be 1 and I have 2 rows of data consisting of items and quantity 假设id_invoice为1,我有2行数据,其中包含项目和数量

from form: 来自表格:

id_ items | name    | quantity 
    1     | brake   |    2 
    2     | muffler |    1 

So how do i insert this in to database like this? 那么我如何将其插入数据库中呢?
From my form I set it as array. 从我的表格,我将其设置为数组。 I managed to get only 1 data inserted into the database. 我设法只将1个数据插入到数据库中。

it's because you call exit() function inside your loop, that function stops script 这是因为您在循环内调用了exit()函数,该函数停止了脚本

foreach($_POST['items'] as $row=>$itm)
{
   $itm2=mysql_real_escape_string($itm);
   $qty2=mysql_real_escape_string($_POST['quantity'][$row]);

echo $sql="INSERT INTO invoiceinventory (id,id_invoic,id_invent,quantity_buy)VALUES('','1', '$itm2', '$qty2')";
$result = mysql_query($sql) or die(mysql_error());
exit(); //here you got serious problem


}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM