php pdo将字段表动态jquery插入到mysql中

时间:2017-01-16 07:38:41

标签: php mysql pdo

我有动态表输入字段。我将使用 PHP PDO

插入 MySQL

我的表动态:

<?php 
$query  = "SELECT * FROM my_table WHERE  id LIKE '%$id%'";
$search = mysql_query($query ) or die(mysql_error());


$name_list = array();
while ($row = mysql_fetch_array($search)) {
    $name_list[] = $row['name'].":\n,";
}

$parts = array("Part 1 :", "Part 2 :", "Part 3 :","Part 4 :", "Part 5 :");

$email_body = "Product:\n" .str_replace($parts, $name_list, $content);

?>

enter image description here

我的PHP PDO插入MySQL:

<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>

这个插入工作只有1行....如何插入动态行表?

1 个答案:

答案 0 :(得分:0)

Airis我只更改了保存操作块

保持所需的任何一个字段(我通过将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....";
    }

}

}