2011-05-26 37 views
0

我有,例如:fruit_store ID 水果 價格在mysql表做多輸入一次與一個MySQL中 表提交按鈕

和我有格式如:

<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我不知道幫助我請!

+0

你現在如何插入值?你做了什麼? – RRStoyanov 2011-05-26 15:59:47

回答

1

使用[]中輸入名稱作爲這裏

<input name='fruit_input[]' .... /> 

然後在PHP當通過

if (is_array($_POST['fruit_input'])){ 
    foreach ($_POST['fruit_input'] as $key=>$value){ 
     $price=$_POST['fruit_price'][$key]; 
     ... 
0

接收後的數據,循環你需要把一些PHP代碼,看看哪些領域已存在於陣列中 使用

<?php 

if(! empty($_POST)) 
{ 

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

    mysql_query($sql); 

} 
?> 

to c到底有多少值出現後陣列中使用

的print_r($ _ POST)

我希望你從這裏向前理解。