我想提交这个表单到DB php


I want to submit this form into DB php

我想在下面插入这个给定的表单数据数据库,但我不知道如何做到这一点,这是关于将产品插入到多个仓库与不同的数量,当对仓库名称复选框被选中比数量文本框出现。

这是我的PHP代码

<form name="form1" method="post" action="product_insert.php" enctype="multipart/form-data">
  <table>
    <tr>
      <td width="274" align="right" height="25"><strong>Product Name :</strong></td>
      <td><input type="text" name="wproname" value=""  /></td>
    </tr>
    <tr>
      <td width="274" align="right" height="25"><strong>Select Warehouse :</strong></td>
      <td width="500"><table style="border:none">
          <tr >
            <td> Select </td>
            <td> Name </td>
            <td> Quantity </td>
          </tr>
          <?php 
    $sql="select * from tbl_warehouse where w_flag='1'"; 
    $result=ExecuteGetRows($sql);   
    $num_rows=count($result); ?>
          <?php for($i=0;$i<$num_rows;$i++){ ?>
          <tr>
            <td><input type="checkbox" name="chk<?php echo $result[$i]['w_id'];?>" value="<?php echo $result[$i]['w_id'];?>" id="chk<?php echo $result[$i]['w_id'];?>" onChange="display<?php echo $result[$i]['w_id'];?>();" />
            </td>
            <td><?php echo $result[$i]['w_name'];?></td>
            <td><input type="text" name="qty<?php echo $result[$i]['w_id'];?>" id="qty<?php echo $result[$i]['w_id'];?>" style="display:none" />
             </td>
          </tr>
          <script>
function display<?php echo $result[$i]['w_id'];?>()
{
if(document.getElementById("chk<?php echo $result[$i]['w_id'];?>").checked)
{
document.getElementById("qty<?php echo $result[$i]['w_id'];?>").style.display="block";
}
if(!document.getElementById("chk<?php echo $result[$i]['w_id'];?>").checked)
{
document.getElementById("qty<?php echo $result[$i]['w_id'];?>").style.display="none";
}
}
</script>
          <?php } ?>
        </table></td>
    </tr>
       <tr>
      <td align="right"></td>
      <td width="296"><input type="submit" name="Submit" value="Add New" align="middle" class="button login_btn"/></td>
    </tr>
  </table>
</form>

我用这段php代码向数据库插入数据

$sqls=mysql_query("select * from tbl_warehouse");
while($result=mysql_fetch_array($sqls)) {
    $w = $result['w_id'];
    echo $_POST['chk'.$w];
    foreach($_POST['chk'.$w] as $key=>$val) {
        echo $_POST['chk'.$w];
        $sql = "INSERT INTO tbl_product(p_id,w_id,p_name,p_qty) values ('','".$wid."','".$wproname."','".$qty."')"; 
        mysql_query($sql);  
    }
}

在插入语句的values列表中不需要前面的逗号。所以修改这个:

"INSERT INTO tbl_product(p_id,w_id,p_name,p_qty) values ('','".$wid."','".$wproname."','".$qty."')";

:

"INSERT INTO tbl_product(p_id,w_id,p_name,p_qty) values ('".$wid."','".$wproname."','".$qty."')";