Mysql数据没有存储在数组中的第二行

时间:2017-09-08 12:29:55

标签: php mysql arrays mysqli

我试图使用mysqli:bind :: param一次插入两行,因为少数数据必须在mysql的两行中重复,并且很少有数据必须根据名称[]的数组进行更改。但是我只面对索引为0的数组的问题是插入mysql虽然在print_r($ sql)中显示两次为真,这里是插入数据的函数:

function insertSellingItem($customer_details,$po_no,$new_customer,$date,$address,$offer_no,$gstin,$dispatched,$invoice_no,$state,$invoice_date,$code,$challan_no,$remarks,$challan_date,&$serial_no,&$mat_des,&$pl_serial_no,&$hsn_code,&$unit,&$purchase_rate,&$tax_amount,&$total_cost,&$rate,&$quantity,&$item_value,&$discount,&$sgst,&$cgst,&$igst,&$amount,$pay_cost){
global $mysqli;
$stmt = $mysqli->prepare("INSERT INTO sellItems(
    customer_details,
    po_no,
    new_customer,
    date,
    address,
    offer_no,
    gstin,
    dispatched,
    invoice_no,
    state,
    invoice_date,
    code,
    challan_no,
    remarks,
    challan_date,
    serial_no,
    mat_des,
    pl_serial_no,
    hsn_code,
    unit,
    purchase_rate,
    tax_amount,
    total_cost,
    rate,
    quantity,
    item_value,
    discount,
    sgst,
    cgst,
    igst,
    amount,
    pay_cost
)
VALUES(
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?,
    ?
)");
$stmt->bind_param("ssssssssssssssssssssssssssssssss",$customer_details,$po_no,$new_customer,$date,$address,$offer_no,$gstin,$dispatched,$invoice_no,$state,$invoice_date,$code,$challan_no,$remarks,$challan_date,$serial_no,$mat_des,$pl_serial_no,$hsn_code,$unit,$purchase_rate,$tax_amount,$total_cost,$rate,$quantity,$item_value,$discount,$sgst,$cgst,$igst,$amount,$pay_cost);
$stmt->execute();
$inserted_id = $mysqli->insert_id;
$stmt->close();
if($inserted_id>0)
{
    return true;
}
else
{
    return false;
}}

循环如何在此函数中发送数据:

if(!empty($mat_des)){
for($i = 0; $i<count($mat_des); $i++) {
    $sql = insertSellingItem($customer_details,$po_no,$new_customer,$date,$address,$offer_no,$gstin,$dispatched,$invoice_no,$state,$invoice_date,$code,$challan_no,$remarks,$challan_date,$serial_no[$i],$mat_des[$i],$pl_serial_no[$i],$hsn_code[$i],$unit[$i],$purchase_rate[$i],$tax_amount[$i],$total_cost[$i],$rate[$i],$quantity[$i],$item_value[$i],$discount[$i],$sgst[$i],$cgst[$i],$igst[$i],$amount[$i],$pay_cost);
    print_r($sql);
}}

其中print_r(($ mat_des));显示计数2,因为我传递了name = mat_des [];

中的两行

任何建议都将受到高度赞赏!

0 个答案:

没有答案