我使用$ _POST獲取order_id的值,但它並沒有安靜地立即獲取。我需要先點擊按鈕「顯示食物」或任何按鈕(如下圖所示)彈出我想輸出的表格。如何獲取文本框的值並在查詢中使用
如果我將WHERE order_id = $ order_id更改爲WHERE order_id = 724,它將立即彈出該數字的值(724),但它是食物表中所有我的訂單的輸出。所以我的問題是如何輸出特定order_id的正確輸出?
例如我有2個order order_id 1和order_id 2,1的值是漢堡和匹薩,2的值是沙拉和三明治,所以當我點擊1時,那個食物表的值只是漢堡和匹薩然後當我點擊2的值應該是沙拉和三明治不漢堡和披薩。
This is after I click Show Food or any button
我希望你明白我的解釋,我希望對你有所幫助你們,謝謝!
更新:我忘了提及這是在我的訂單裏面。只是要清楚
<div class="form-group">
<label for="order_id" class="col-sm-2 control-label">Order ID</label>
<div class="col-lg-3">
<input type="text" input style="width:500px" class="form-control" name="ORDER_ID" id="ORDER_ID" placeholder="" value="" required="required" readonly>
</div>
</div>
<?php
$order_id = trim(addslashes($_POST['ORDER_ID']));
$sql = "SELECT food_name, special_request, quantity, amount
FROM cart_tbl
WHERE order_id=$order_id";
$result = mysqli_query(connection2(), $sql);
?>
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>Food</th>
<th>Special Request</th>
<th>Quantity</th>
<th>Amount</th>
</tr>
</thead>
<?php
if(mysqli_num_rows($result)>0) {
while($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><?php echo $row["food_name"];?></td>
<td><?php echo $row["special_request"];?></td>
<td><?php echo $row["quantity"];?></td>
<td><?php echo $row["amount"];?></td>
</tr>
<?php
}
}
?>
</table>
</div>
<div class="modal-footer">
<button type="submit" input
style="background-color: #FF0000; color:white; float:left"
name="showFood" id="showFood" class="btn btn-primary"
onclick="if(!confirm('Are you sure you want to see food order?')){return false;}" > Show Food
</button>
<button type="submit" input
style="background-color: #4CAF50; color:white"
name="submitDelivered" id="submitDelivered"
class="btn btn-primary"
onclick="if(!confirm('Are you sure you want to deliver order?')){return false;}" > Delivered
</button>
<button type="submit" input
style="background-color: #0000FF; color: white"
name="submitAccept" id="submitAccept" class="btn btn-primary"
onclick="if(!confirm('Are you sure you want to accept order?')){return false;}" <?php if($_POST['order_status']="Accepted"): ?>.disabled <?php endif ?>> Accept
</button>
<button type="button" style="background-color: #FFFF00;color: black"
class="btn btn-success" data-toggle="modal"
data-target="#myDropdown"> Send
</button>
<button type="submit" input
style="background-color: #f44336; color: white"
name="submitCancel" class="btn btn-danger"
onclick="if(!confirm('Are you sure you want to cancel order?')){return false;}">Cancel
</button>
</div>
好像你的MySQL查詢失敗。嘗試使用'var_dump($ sql)'來確保查詢格式良好,數據庫中存在$ _POST ['order_id']'的值。 – Cobolt
@Cobolt是的,它存在於我的數據庫中 – zxczxczxc
根據你的錯誤消息,'$ _POST ['ORDER_ID']'沒有被定義,因此你生成的SQL查詢是無效的,而'mysqli_query'的結果是'false'一個'mysqli_result'的實例。試試'$ _POST ['order_id']',它可能區分大小寫。如果這不起作用,請執行'var_dump($ _ POST);'以確保發佈表單時''_POST'數組中存在'order_id'變量。 – Cobolt