我在mysql中有例子 table: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中,我不知道请帮助我!
答案 0 :(得分:1)
在输入名称中使用[],如此处
<input name='fruit_input[]' .... />
然后在接收帖子数据时在php中循环
if (is_array($_POST['fruit_input'])){
foreach ($_POST['fruit_input'] as $key=>$value){
$price=$_POST['fruit_price'][$key];
...
答案 1 :(得分:0)
你需要放一些php代码来查看post数组中存在哪些字段 使用
<?php
if( ! empty( $_POST ) )
{
$sql = "insert into table ......values ...";
mysql_query($sql);
}
?>
检查post数组中使用的值数
的print_r($ _ POST)
我希望你能从这里开始理解。