-1
即时通讯新的php和sql现在,所以我混淆了什么是错误的代码(需要做)cart_tbl(order_id)food_name,special_request,数量,金额等于我的order_id order_tbl。当我的order_tbl和cart_tbl的order_id都相同时。我的输出将是该表的值。这是我现在的代码。如何从db中选择一个值
<?php
$connect = mysqli_connect ("localhost", "root", "" , "db");
if(isset($_POST['order_id'])){
$asd = ($_POST['order_id']);
$sql = "SELECT food_name, special_request, quantity, amount
FROM cart_tbl
WHERE order_id='$asd'";
$result = mysqli_query($connect, $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>
我得到错误“未定义的变量:结果”我不能得到我的文本框的值。下面是我的代码<?php $ connect = mysqli_connect(“localhost”,“root”,“”,“db”); ($ set($ _ POST ['order_id'])){ \t $ order_id = $ _POST [“order_id”]; $ sql =“SELECT food_name,special_request,quantity,amount FROM cart_tbl WHERE order_id ='$ order_id'”; $ result = mysqli_query($ connect,$ sql); } ?> – Blank
@Blank *“未定义的变量:结果”我无法获得我的文本框的值。*,这是一个非常不同的问题,而不是你在问题中提出的问题。确保输入元素中的'name'属性正确。另外,请执行'var_dump($ _ POST);'并确保键和相应的值是正确的。顺便说一句,你在哪条线* Undefined变量:结果*错误? –
我使用会话,但我不能得到order_id的文本框的值。 BTW它在if(mysqli_num_rows($ result)> 0)线我想。 – Blank