php pdo вставка полей таблица динамический jquery в mysql

У меня есть динамические поля ввода таблицы .Я буду вставлять в MySQL с PHP PDO

Моя Таблица Динамическая:

<tbody >
<tr class="item-row" >
    <td></td>
    <td><input name="user_codefani[]"  value="" id="codefani" tabindex="1" /></td>
    <td><input name="user_codekala[]"  value="" id="codekala"/></td>
    <td><input name="user_sharhkala[]" value="" id="sharhkala"/></td>
    <td><input name="user_zamantahvilkala[]" value="" id="zamantahvilkala"/></td>
    <td><input name="user_keshvar[]"   value="" id="keshvar" /></td>
    <td><input name="user_itemQty[]"   value="" id="itemQty1" /></td>
    <td><input name="user_metr[]"      value="" id="metr" /></td>
    <td><input name="user_gheymatround[]"value="" id="gheymatround1" /></td>
    <td><input name="user_multiply[]"  value="" id="gheymatkol1" /></td>
    <td><input name="user_infocode[]"  value="" id="infocode" /></td>
</tr>

Введите описание изображения здесь

Моя PHP PDO вставка в MySQL:

<?php
require_once 'dbconfig.php';
$stmt_edit = $DB_con->prepare('SELECT shomarepishfactor 
               FROM pishfactorriali ORDER BY userID DESC LIMIT 1;');
$stmt_edit->execute(array(':uid'=>$id));
$edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC);
extract($edit_row);
if(isset($_POST['btnsave']))
{
    $usercodefani = $_POST['user_codefani'];
    $usercodekala = $_POST['user_codekala'];
    $usersharhkala = $_POST['user_sharhkala'];
    $userzamantahvilkala = $_POST['user_zamantahvilkala'];
    $userkeshvar = $_POST['user_keshvar'];
    $useritemQty = $_POST['user_itemQty'];
    $usermetr = $_POST['user_metr'];
    $usergheymatround = $_POST['user_gheymatround'];
    $usermultiply = $_POST['user_multiply'];
    $userinfocode = $_POST['user_infocode'];
    if(!isset($errMSG))
    {
        $stmt = $DB_con->prepare('INSERT INTO 
                   pishfactorriali(codefani,codekala,sharhkala,
                   zamantahvilkala,keshvar,itemQty,
                   metr,gheymatround,multiply,infocode) 
                 VALUES(:ucodefani,:ucodekala,:usharhkala, 
                      :uzamantahvilkala ,:ukeshvar,:uitemQty, 
                :umetr,:ugheymatround,:umultiply, :uinfocode)');
        $stmt->bindParam(':ucodefani',$usercodefani);
        $stmt->bindParam(':ucodekala',$usercodekala);
        $stmt->bindParam(':usharhkala',$usersharhkala);
        $stmt->bindParam(':uzamantahvilkala',$userzamantahvilkala);
        $stmt->bindParam(':ukeshvar',$userkeshvar);
        $stmt->bindParam(':uitemQty',$useritemQty);
        $stmt->bindParam(':umetr',$usermetr);
        $stmt->bindParam(':ugheymatround',$usergheymatround);
        $stmt->bindParam(':umultiply',$usermultiply);
        $stmt->bindParam(':uinfocode',$userinfocode);
        if($stmt->execute())
        {
            $successMSG = "new record succesfully inserted ...";
            header("refresh:2;index.php"); 
        }
        else
        {
            $errMSG = "error while inserting....";
        }
    }
}?>

эта вставка работает только для 1 строки ….как вставить динамическую таблицу строк ?

1 ответ

  1. Airis I изменил только блок действия сохранить,

    Сохранить любое поле требуется (я проверяю, сохраняя itemQty как req)

    if(isset($_POST['btnsave']))
    

    {

    if(!isset($errMSG))
    {
        $itemcount=count($user_itemQty);$errstatus=0;
        for($itemC=0;$itemC<$itemcount;$itemC++){
            $usercodefani = $_POST['user_codefani'][$itemC];
    $usercodekala = $_POST['user_codekala'][$itemC];
    $usersharhkala = $_POST['user_sharhkala'][$itemC];
    $userzamantahvilkala = $_POST['user_zamantahvilkala'][$itemC];
    $userkeshvar = $_POST['user_keshvar'][$itemC];
    $useritemQty = $_POST['user_itemQty'][$itemC];
    $usermetr = $_POST['user_metr'][$itemC];
    $usergheymatround = $_POST['user_gheymatround'][$itemC];
    $usermultiply = $_POST['user_multiply'][$itemC];
    $userinfocode = $_POST['user_infocode'][$itemC];
    
            $stmt = $DB_con->prepare('INSERT INTO pishfactorriali(codefani,codekala,sharhkala,zamantahvilkala,keshvar,itemQty,metr,gheymatround,multiply,infocode) VALUES(:ucodefani,:ucodekala,:usharhkala, :uzamantahvilkala ,:ukeshvar,:uitemQty, :umetr,:ugheymatround,:umultiply, :uinfocode)');
        $stmt->bindParam(':ucodefani',$usercodefani);
        $stmt->bindParam(':ucodekala',$usercodekala);
        $stmt->bindParam(':usharhkala',$usersharhkala);
        $stmt->bindParam(':uzamantahvilkala',$userzamantahvilkala);
        $stmt->bindParam(':ukeshvar',$userkeshvar);
        $stmt->bindParam(':uitemQty',$useritemQty);
        $stmt->bindParam(':umetr',$usermetr);
        $stmt->bindParam(':ugheymatround',$usergheymatround);
        $stmt->bindParam(':umultiply',$usermultiply);
        $stmt->bindParam(':uinfocode',$userinfocode);
        if($stmt->execute())
        {
    
    
        }
        else
        {
            $errstatus =1;
        }
    
            }
    
            if($errstatus==0)
        {
            $successMSG = "new record succesfully inserted ...";
            header("refresh:2;index.php"); 
        }
        else
        {
            $errMSG = "There is some error while inserting....";
        }
    
    }
    

    }