目前我正在开发一个物流网站,其想法如下:
我们有一个取件地址,我们可以有多个送货地址。
这是我们使用的表格:
id | order_id | user_id | company | address | postal | city | order_number | license_plate | qty | unit | instructions | type | status
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
0 | 10000 | 1 | Company A | Street 1 | 00000 | City A | 123123123 | xx-xxx-x | 1 | M3 | blabla | P | 0
1 | 10000 | 1 | Company A | Street 1 | 00000 | City B | 123123123 | xx-xxx-x | 1 | M3 | blabla | D | 0
2 | 10000 | 1 | Company A | Street 1 | 00000 | City B | 123123123 | xx-xxx-x | 1 | M3 | blabla | D | 0
一个取件地址(type = P)可以有多个送货地址。
根据order_id显示所有地址。运输商需要填写每个地址的order_number,qty和unit字段。
我们使用以下php文件来执行表单。但是当我填写第一个表单上的字段并单击保存order_number时,qty和unit将填入所有3个表行。
<?php
include_once 'db.php';
/* code for update orders */
if(isset($_GET['edit']))
{
$SQL = $MySQLiconn->query("SELECT * FROM orders WHERE order_id=".$_GET['edit']);
$getROW = $SQL->fetch_array();
}
if(isset($_POST['update']))
{
$SQL = $MySQLiconn->query("UPDATE orders SET order_number='".$_POST['order_number']."',
qty='".$_POST['qty']."',
unit='".$_POST['unit']."',
status='".$_POST['status']."'
WHERE order_id=".$_GET['edit']);
}
/* code for data update */
?>
<?php include_once 'header.php'; ?>
<div class="container">
<div id="pickupform">
<form method="post" class="form-horizontal">
<fieldset>
<?php
$res = $MySQLiconn->query("SELECT * FROM orders WHERE type='P' AND order_id=".$_GET['edit']);
while($row=$res->fetch_array())
{
?>
<!-- Delivery Address-->
<div class="formcontainer col-push-md-4">
<div class="form-group">
<label class="col-md-4 control-label">Afleveradres</label>
<div class="col-md-8">
<p><?php echo $row['company']; ?><br/>
<?php echo $row['address']; ?><br/>
<?php echo $row['postal']; ?> <?php echo $row['city']; ?></p>
</div>
</div>
<!-- Ordernumber -->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Ordernummer / Lieferschein</label>
<div class="col-md-8">
<input id="order_number" name="order_number" type="text" placeholder="<?php echo $row['order_number']; ?>" class="form-control input-md" value="<?php if(isset($_GET['edit'])) echo $getROW['order_number']; ?>">
</div>
</div>
<!-- Quantity / Unit -->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Hoeveelheid / Quantity</label>
<div class="col-md-8">
<div class="input-group">
<input id="qty" name="qty" type="text" placeholder="Bijv. 100" class="form-control input-md" value="<?php if(isset($_GET['edit'])) echo $getROW['qty']; ?>" />
<span class="input-group-btn" style="width:0px;"></span>
<input id="unit" name="unit" type="text" placeholder="Bijv. M3" class="form-control input-md" value="<?php if(isset($_GET['edit'])) echo $getROW['unit']; ?>"value="test2" style="margin-left:-1px" />
</div>
</div>
</div>
<!-- Send Consignment -->
<input type="hidden" name="status" value="<?php if(isset($_GET['edit']))?>1"/>
<div class="form-group">
<label class="col-md-4 control-label" for="update"></label>
<div class="col-md-8">
<?php if(isset($_GET['edit'])) { ?>
<button type="submit" class="btn btn-primary" name="update">Opslaan</button>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</fieldset>
</form>
</div>
</div>
<div class="container">
<div id="deliveryform">
<form method="post" class="form-horizontal">
<fieldset>
<?php
$res = $MySQLiconn->query("SELECT * FROM orders WHERE type='D' AND order_id=".$_GET['edit']);
while($row=$res->fetch_array())
{
?>
<div class="formcontainer col-push-md-4">
<div class="form-group">
<label class="col-md-4 control-label">Afleveradres</label>
<div class="col-md-8">
<p><?php echo $row['company']; ?><br/>
<?php echo $row['address']; ?><br/>
<?php echo $row['postal']; ?> <?php echo $row['city']; ?></p>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Ordernummer / Lieferschein</label>
<div class="col-md-8">
<input id="order_number" name="order_number" type="text" placeholder="<?php echo $row['order_number']; ?>" class="form-control input-md" value="<?php if(isset($_GET['edit'])) echo $getROW['order_number']; ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Hoeveelheid / Quantity</label>
<div class="col-md-8">
<div class="input-group">
<input id="qty" name="qty" type="text" placeholder="Bijv. 100" class="form-control input-md" value="<?php if(isset($_GET['edit'])) echo $getROW['qty']; ?>" />
<span class="input-group-btn" style="width:0px;"></span>
<input id="unit" name="unit" type="text" placeholder="Bijv. M3" class="form-control input-md" value="<?php if(isset($_GET['edit'])) echo $getROW['unit']; ?>"value="test2" style="margin-left:-1px" />
</div>
</div>
</div>
<input type="hidden" name="status" value="1"/>
<div class="form-group">
<label class="col-md-4 control-label" for="update"></label>
<div class="col-md-8">
<?php if(isset($_GET['edit'])) { ?>
<button type="submit" class="btn btn-primary" name="update">Opslaan</button>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</fieldset>
</form>
</div>
</div>
<?php include_once 'footer.php'; ?>
我不是那个有PHP的家庭成员,你能帮助我解决这个问题吗?因此,根据地址,我需要提交设置。
答案 0 :(得分:0)
在第一个表单中添加隐藏字段:
<input type='hidden' name='type' value='P' />
这会将值'P'提交到$ _POST ['type']。
然后修改更新查询以在WHERE子句中使用此值:
....WHERE order_id=".$_GET['edit'])." AND type='".$_POST['type']."';
(不要忘记单引号 - 'P'是一个字符串。) 这应该只更新匹配的行。
然后,使用值'D'对第二种形式执行相同的操作。