一个提交按钮一次在mysql表中进行多个输入

问题描述

| 我有例如MysqL 桌子:fruit_store ID 水果 价钱 我有这样的形式:
<a href=\"#\" id=\"add_input\">Add</a> 
<a href=\"#\" id=\"remove_input\">Remove</a>  
    <form action=\"<?PHP $_SERVER[\'PHP_SELF\'] ?>\" method=\"POST\">
        <table id=\"workTbl\">
            <tr>
                <td>Fruit</td>
                <td>Price</td>
            </tr>
        </table>
        <p><input name=\"submit\" type=\"submit\" id=\"submit_tbl\" /></p>
       </form>
并有jQuery代码
$(function(){
    $(\"#add_input\").click(function(){
        $(\"#workTbl\").append(\"<tr><td><input name=\'fruit_input\' type=\'text\' /></td><td><input name=\'price_input\' type=\'text\' /></td></tr>\");
    });
    $(\"#remove_input\").click(function(){ 
         $(\'#workTbl input:last\').remove();
         $(\'#workTbl input:last\').remove();           
    })
});
我想问一下如何使用一个提交按钮或多种形式将多个输入插入到MysqL表fruit_store中,我不知道请帮我!     

解决方法

如此处所示,在输入名称中使用[]
   <input name=\'fruit_input[]\' .... />
然后在php中,在收到发布数据后,遍历
  if (is_array($_POST[\'fruit_input\'])){
   foreach ($_POST[\'fruit_input\'] as $key=>$value){
        $price=$_POST[\'fruit_price\'][$key];
        ...
    ,您需要放置一些php代码以查看post数组中存在哪些字段 采用
<?php 

 if( ! empty( $_POST ) )
{

   $sql = \"insert into table  ......values ...\";

   mysql_query($sql);

}
?>
检查post数组使用中存在多少个值   print_r($ _ POST) 我希望您能从这里开始理解。