gpt4 book ai didi

php - 在php中保存动态添加的文本框

转载 作者:行者123 更新时间:2023-11-30 00:56:56 24 4
gpt4 key购买 nike

嗨,我正在开发一个表单,它能够在单击按钮时添加表行,但问题是我的 php for 循环正在保存第一行,而不保存其他文本框值。我被困住了。这是我的代码

<form class="form-horizontal" name="invoice" method="POST">
<div id="div-2" class="accordion-body collapse in body">
<div style="max-height:300px;overflow: auto; border: 0px solid;">
<div style="float:left; margin-right:-8220000px;">
<table id="data" border="1px" width="90%">

<tr>
<td width="60px" align="center"> <label class="control-label">Sr No.</label></td>
<td width="250px" align="center"><label class="control-label">Item Name</label></td>
<td width="90px" align="center"><label class="control-label">Qty</label></td>
<td width="50px" align="center"><label class="control-label">Unit</label></td>
<td width="100px" align="center"><label class="control-label">Rate</label></td>
<td width="120px" align="center"><label class="control-label">Amount</label></td>
<td width="200px" align="center"><label class="control-label">Marks& Nos</label></td>
<td width="250px" align="center"><label class="control-label">Description</label></td>
</tr>
<tr>
<td align="left"><input type="text" size="6" maxlength="6" maxlength="6" name="srno_0" class="sno form-control"/></td>
<td align="left">
<select data-placeholder="Item" name="item_0" class="form-control" >
<option value=""></option>
<?php
$mown = mysql_query("SELECT code, `name` FROM `item`") or die(mysql_error());
while ($trow = mysql_fetch_array($mown)) {
echo "<option value=$trow[code]>$trow[name]</option>";
}
?>
</select>
</td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="qty_0" class="qty form-control" style='text-align:right'/></td>
<td align="left">
<input type="text" size="6" maxlength="6" name="unit_0" class="unit form-control"/>
</td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="rate_0" class="rate form-control" style='text-align:right'/></td>
<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="amt_0" id="amount" class="amt form-control" style='text-align:right' readonly/></td>
<td align="center"><input type="text" size="6" name="marks_0" class="trip form-control"/></td>
<td align="center"><textarea name="descrip_0" cols="90" rows='1' class="desc form-control"></textarea></td>

</tr>
</table>
</div>

</div>
<table border='0' width='100%'>


<tr>
<td width="150px">
<input type="button" id="addnew" class="btn btn-success btn-lg" name="addnew" value="+" />
<input type="hidden" id="items" name="items" value="<?php echo ($addflag == 0) ? $ctr : 1; ?>" />
</td><td width="240px"></td><td width="140px"></td><td width="200px" align="right"><label for=""><font color="black" size="3px">SubTotal</font><span></span></label></td>
<td width="200px"><input id="total" type="text" name="total" class="form-control" value="<?php echo ($addflag == 0) ? $get['total'] : "0.00"; ?>" readonly style='text-align:right'></td>
</tr>
here is my jquery code
<script type='text/javascript'>
$(document).ready(function() {
$('#data').on('keyup', '.qty, .rate, .amt', calculateRow);
$('#data').on('blur', '.desc', addrows);

function addrows(){

var ctr = $('#items').val();
$.post('bmt_invsrch.php', {ctr: ctr}, function(data) {
$(data).appendTo('#data');
ctr++;
$('#items').val(ctr);
});
}

$('#addnew').click(function() {
addrows();
});
});


</script>

这是我的 php

for ($i = 0; $i<$count; $i++){
$msrno = $_POST["srno_$i"];
$mitem = $_POST["item_$i"];
$mqty = $_POST["qty_$i"];
$munit = $_POST["unit_$i"];
$mrate = $_POST["rate_$i"];
$mamt = $_POST["amt_$i"];
$mmarks = $_POST["marks_$i"];
$mdescrip = $_POST["descrip_$i"];

mysql_query("INSERT INTO `saletran`(vouchno, srno, item, qty, unit, rate, amt, marks, descrip)
VALUES('$mvouch', '$msrno', '$mitem', '$mqty', '$munit', '$mrate', '$mamt', '$mmarks', '$mdescrip')") or die(mysql_error());



}

最佳答案

您可以对输入字段进行分组,如下所示

<form method='post'>
<input type='text' name='test[]' />
<input type='text' name='test[]' />
<input type='text' name='test[]' />
<input type='text' name='test[]' />

<input type='submit' value='submit' name='submit'/>
</form>

当您提交此表单时,结果将类似于

Array
(
[test] => Array
(
[0] => 21
[1] => 212
[2] => 121
[3] => 21
)

[submit] => submit
)

关于php - 在php中保存动态添加的文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20473713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com