我不知道如何使用mysql将多个输入插入数据库。我想做的是做一个订单,你可以在其中插入多个项目,每个项目都有一个数量和价格。我是否应该对每个输入使用相同的字段名,后跟[]以使其成为数组。那么插入sql看起来会是什么样子呢?
<form action="processinvoice.php" method="post">
<label>Invoice Number</label>
<input type="text" name="invoicenumber" value="Enter Invoice Number">
<p><label>Vendor's ID</label>
<input type="text" name="vendorid" value="Enter Vendor's ID"></p>
<!-- Product code begining -->
<label>Items sold</label>
<select name="proid[]" >
<?php
$stmt = $dbcon->prepare("SELECT * FROM products");
$stmt->execute();
while ($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
?>
<option value=" <?php echo $pid; ?> "><?php echo $pname; ?></option>
<?php
} ?>
</select>
<label>Quantity</label>
<input type="text" name="tquantity[]" value="Enter quantity">
<label>Price</label>
<input type="text" name="saleprice[]" value="Enter price">
<p></p><select name="proid[]" >
<?php
$stmt = $dbcon->prepare("SELECT * FROM products");
$stmt->execute();
while ($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
?>
<option value=" <?php echo $pid; ?> "><?php echo $pname; ?></option>
<?php
} ?>
</select>
<label>Quantity</label>
<input type="text" name="tquantity[]" value="Enter quantity">
<label>Price</label>
<input type="text" name="saleprice[]" value="Enter price">
<p></p><select name="proid[]" >
<?php
$stmt = $dbcon->prepare("SELECT * FROM products");
$stmt->execute();
while ($row=$stmt->fetch(PDO::FETCH_ASSOC)) {
extract($row);
?>
<option value=" <?php echo $pid; ?> "><?php echo $pname; ?></option>
<?php
} ?>
</select>
<label>Quantity</label>
<input type="text" name="tquantity[]" value="Enter quantity">
<label>Price</label>
<input type="text" name="saleprice[]" value="Enter price">
<!-- Product code END -->
<input type="submit" name="submit" value="submit">我试图做的是:插入多个项目与数量和价格的每一个。所有项目都将显示相同的发票编号和供应商id。
发布于 2019-06-23 20:49:20
如果要在MySQL数据库中插入多条记录,请执行以下操作:
插入tbl_name (a,b,c)值(1,2,3),(4,5,6),(7,8,9);
https://stackoverflow.com/questions/56723629
复制相似问题