【发布时间】:2018-10-04 21:55:27
【问题描述】:
我正在使用 HTML 和 PHP 创建一个表单。我创建了一个表单,我想提交并将该数据保存在数据库中。
我正在尝试提交一个包含来自 while 循环的数据的表单。所有输入值都由 while 循环生成。
代码如下所示。
<table width="1348" border="0" class="table table-striped" >
<tr>
<td width="106"> </td>
<td width="332"><strong>Product Code</strong></td>
<td width="375"><strong>Product Name</strong></td>
<td width="211"><strong>QTY</strong></td>
</tr>
<?php
$i = 0;
$rowset = mysql_query("select * from product_detail where productID='".$data['productCode']."'");
while($stuff = mysql_fetch_array($rowset)){
?>
<tr>
<td><input type="text" name="code[<?php echo $i?>]" value="<?php enter code hereecho $stuff['code'];?>"/></td>
<td><input type="text" name="name[<?php echo $i?>]" value="<?php echo $stuff['name'];?>" size="50"/></td>
<td><input type="text" name="qty[<?php echo $i?>]" value="<?php echo $stuff['qty'];?>" size="10"/></td>
</tr>
<?php $i++; }?>
<tr id="last">
</table>
<input type="submit" name="save id="save" class="btn btn-primary btn-lg"/>
这是将数据添加到数据库的代码。
$code=$_POST['code'.$i];
$name=$_POST['name'.$i];
$qty=$_POST['qty'.$i];
$query = mysqli_query($con,"insert into stock(productCode, productName, qty) values ('".$code."', '".$name."','".$qty."')") or die(mysqli_error($con));
【问题讨论】:
-
您需要从表格中提交数据吗?
-
查看您的
$_POST数组。你也对 SQL 注入持开放态度。参数化。还要在任何地方使用mysqli,不要再使用mysql_*。 -
是的,我需要从表格中提交我的数据@diego 得到它 chirs85
-
为什么要使用删除的mysql扩展来获取表并使用mysqli扩展来插入?
-
$lagu vs $stuff 是什么?
标签: php html mysql while-loop