0

i want to insert this below given form data to database, but i dont know how to do this, it is about inserting product to multiple warehouse with different quantities, when checkbox against the warehouse name is checked than the quantity textbox appears.

and this is my PHP code

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

And I am using this php code for inserting data to the database

$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);  
    }
}
4

1 回答 1

0

您不需要插入语句中值列表中的前导逗号。所以改变这个:

"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."')";
于 2012-12-22T13:51:34.423 回答