嘿,我正试图从MySQL中检索数据,其中date=CURDATE(),但它显示了某种错误
注意:未定义的变量:第48行C:''wamp''www''resturent management''todaysExpenses.php中的stmt
这是我的代码
<div class="container" align="center">
<table cellpadding="5px" cellspacing="5px" width="75%">
<tr>
<th>ID</th>
<th>Item name</th>
<th>Item Cost</th>
<th>Item Dated</th>
<th>Incharge</th>
</tr>
<?php
//get all moderators except deleted
if($stmt->prepare("select id, itemName, itemCost, itemDated, itemIncharge from expenses where itemDated = CURDATE()"))
{
$stmt->bind_result($id, $name, $cost, $date, $incharge);
$stmt->execute();
if($stmt->fetch())
{
do
{
?>
<tr>
<td><?php echo $id ?></td>
<td><?php echo $name ?></td>
<td><?php echo $cost ?></td>
<td><?php echo $date?></td>
<td><?php echo $incharge?></td>
</tr>
<?php
}while($stmt->fetch());
}
else
{
//Todo
}
}
?>
</table>
</div>
请帮我纠正这个错误。。。感谢
if($stmt = $mysqli->prepare("select id, itemName, itemCost, itemDated, itemIncharge from expenses where itemDated = CURDATE()"))
好吧,如果$stmt是应该管理prepared语句的变量,那么只有$mysqli(或用于连接到MySQL服务器的变量)具有prepare方法。
我没有看到更多的错误。
如果你需要帮助,请阅读本文。
啊,MySQLi。
您发布的代码中没有定义stmt。必须先为其分配一个对象,然后才能对其进行方法调用。