我使用$ _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