使用一个提交按钮一次在mysql表中进行多个输入 [英] Make multiple inputs in mysql table at once with one submit button
问题描述
我例如在mysql
表中:fruit_store
id
fruit
price
我有表单例如:
< a href =#id =add_input>添加< / a>
< a href =#id =remove_input>移除< / a>
< form action =<?php $ _SERVER ['PHP_SELF']?>方法= POST >
< table id =workTbl>
< tr>
< td>水果< / td>
< td>价格< / td>
< / tr>
< / table>
< p>< input name =submittype =submitid =submit_tbl/>< / p>
< / form>
并且有jquery代码:
<$ p $点击(功能(){
$(#workTbl)。append(< tr> ;< td>< input name ='fruit_input'type ='text'/>< / td>< td>< / td>< input name ='price_input'type ='text' ;< / 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];
...
I have for example in mysql table: fruit_store id fruit price
and I have form like:
<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>
and have jquery code:
$(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();
})
});
I want to ask how to insert multiple inputs into mysql table fruit_store with one submit button or multiple forms i don't know help me please!
use [] in the input name as in here
<input name='fruit_input[]' .... />
then in php upon receiving post data, loop through
if (is_array($_POST['fruit_input'])){
foreach ($_POST['fruit_input'] as $key=>$value){
$price=$_POST['fruit_price'][$key];
...
这篇关于使用一个提交按钮一次在mysql表中进行多个输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!