2015-11-20 98 views
0

目前我正在開發一個物流網站的想法是:在同一個表從一個頁面提交多份表格

我們有一個取件地址,我們可以有多個送貨地址。

這就是我們使用該表:

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 

一個拾地址(類型= P)可以具有多個遞送地址。

根據order_id顯示所有地址。運輸商需要填寫每個地址的order_number,數量和單位字段。

我們使用下面的php文件來執行表單。但是,當我填寫第一個表格中的字段並單擊保存order_number時,所有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']; ?>&nbsp;<?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']; ?>&nbsp;<?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的familiair,你們能幫我解決這個問題嗎?所以每個地址我需要提交設置。

回答

0

內,您的第一種形式,添加一個隱藏字段:

<input type='hidden' name='type' value='P' /> 

這將提交值「P」到$ _ POST [「型」。

然後修改更新查詢的WHERE子句中使用這個值:(不要忘了單引號 - 「P」是一個字符串)

....WHERE order_id=".$_GET['edit'])." AND type='".$_POST['type']."'; 

這應該然後只更新匹配行。

然後,使用值'D'對第二個窗體執行相同的操作。

+0

謝謝,但第二種形式也可以有多個地址,當他到達收貨地址a並且他到達收貨地址2等時,運輸公司需要填寫值。有時一個收貨可能有5個不同的地址送貨地址。 – Wouter

+0

上面的解決方案會根據提交的表單更新每一行匹配order_id和'P'或'D'的行。 – MaggsWeb

+0

是的,我明白了。但是,如果我遇到以下情況,請在下列情況下查看:1張表單和3張交付表單在一個頁面上 – Wouter

相關問題