如何插入多个表数组

时间:2017-03-06 09:30:49

标签: php mysqli

我正在尝试插入数据表格4表格正常插入完成但数据数组 无法查询。请问你能帮帮我吗?

代码:

for ($i = 1; $i <= (int)$_POST["hdnCount"]; $i++) {
    $sql = "INSERT INTO status_b(emp_id,name_baby,date_baby,status_baby,class,age,id_card_baby,stay) VALUES ('" . $_POST["emp_id$i"] . "','" .
            $_POST["name_baby$i"] . "','" .
            $_POST["date_baby$i"] . "','" .
            $_POST["status_baby$i"] . "','" .
            $_POST["class$i"] . "','" .
            $_POST["age$i"] . "','" .
            $_POST["id_card_baby$i"] . "','" .
            $_POST["stay$i"] . "');";
}

$sql = "INSERT INTO personal (st_date,emp_id,emp_date,division,department,sc,name_th,lname_th,blood,name_en, lname_en,per_date,id_card,exp_card,id_fund,date_fund,rate,acc_id,name_bank, m_bank,add_h,district_h,amphoe_h,province_h,add_n,district_n,amphoe_n,province_n, tel_home,tel,images,education,e_major,institution,name_e,tel_e)
VALUES('" . $_POST["st_date"] . "','" .
        $_POST["emp_id"] . "','" .
        $_POST["emp_date"] . "','" .
        $_POST["division"] . "','" .
        $_POST["department"] . "','" .
        $_POST["sc"] . "','" .
        $_POST["name_th"] . "','" .
        $_POST["lname_th"] . "','" .
        $_POST["blood"] . "','" .
        $_POST["name_en"] . "' ,'" .
        $_POST["lname_en"] . "','" .
        $_POST["per_date"] . "','" .
        $_POST["id_card"] . "','" .
        $_POST["exp_card"] . "','" .
        $_POST["id_fund"] . "','" .
        $_POST["date_fund"] . "','" .
        $_POST["rate"] . "','" .
        $_POST["acc_id"] . "','" .
        $_POST["name_bank"] . "' ,'" . 
        $_POST["m_bank"] . "','" .
        $_POST["add_h"] . "','" .
        $_POST["district_h"] . "','" .
        $_POST["amphoe_h"] . "','" .
        $_POST["province_h"] . "','" .
        $_POST["add_n"] . "','" .
        $_POST["district_n"] . "','" .
        $_POST["amphoe_n"] . "','" .
        $_POST["province_n"] . "' ,'" . 
        $_POST["tel_home"] . "','" .
        $_POST["tel"] . "','" .
        $_POST["images"] . "','" .
        $_POST["education"] . "','" .
        $_POST["e_major"] . "','" .
        $_POST["institution"] . "','" .
        $_POST["name_e"] . "','" .
        $_POST["tel_e"] . "');";

$sql .= "INSERT INTO status (name_m,lname_m,date_m,id_card_m,date_r,location,tel_m,status,mary,num_baby)
VALUES
('" . $_POST["name_m"] . "','" .
        $_POST["lname_m"] . "','" .
        $_POST["date_m"] . "','" .
        $_POST["id_card_m"] . "','" .
        $_POST["date_r"] . "','" .
        $_POST["location"] . "','" .
        $_POST["tel_m"] . "','" .
        $_POST["status"] . "','" .
        $_POST["mary"] . "','" .
        $_POST["num_baby"] . "');";



$sql .= "INSERT INTO tax (f_name,f_id,f_date,claim_f,mf_name,mf_id,mf_date,claim_mf,mm_name,
mm_id,mm_date,claim_mm,insurance,num_in,insurance_l,num_inl,unit,num_un,interest,
num_int,support,num_su,donate,num_do,buy,num_b,other,num_o)
VALUES
('" . $_POST["f_name"] . "','" .
        $_POST["f_id"] . "','" .
        $_POST["f_date"] . "','" .
        $_POST["claim_f"] . "','" .
        $_POST["mf_name"] . "','" .
        $_POST["mf_id"] . "','" .
        $_POST["mf_date"] . "','" .
        $_POST["claim_mf"] . "','" .
        $_POST["mm_name"] . "','" .
        $_POST["mm_id"] . "','" .
        $_POST["mm_date"] . "','" .
        $_POST["claim_mm"] . "','" .
        $_POST["insurance"] . "','" .
        $_POST["num_in"] . "','" .
        $_POST["insurance_l"] . "','" .
        $_POST["num_inl"] . "','" .
        $_POST["unit"] . "','" .
        $_POST["num_un"] . "','" .
        $_POST["interest"] . "','" .
        $_POST["num_int"] . "','" .
        $_POST["support"] . "','" .
        $_POST["num_su"] . "','" .
        $_POST["donate"] . "','" .
        $_POST["num_do"] . "','" .
        $_POST["buy"] . "','" .
        $_POST["num_b"] . "','" .
        $_POST["other"] . "','" .
        $_POST["num_o"] . "');";



if (mysqli_multi_query($conn, $sql)) {
    echo "New records created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);

0 个答案:

没有答案