gpt4 book ai didi

php - 为什么这个变量没有被发布并给出错误?

转载 作者:行者123 更新时间:2023-11-29 23:03:11 25 4
gpt4 key购买 nike

为什么 bakeryid 变量没有发布在我的表单中?我收到的错误是

"Notice:Undefined variable bakeryid"

我有两个页面,一个显示表单,第二个是表单的操作。第二种形式也一直说它是未定义的。 bakeryid 是每个蛋糕订单的 ID。

$sql = mysqli_query($con,"SELECT `firstname`, `bakeryid`, `order` FROM cakes");

$bakeryid = $_POST['bakeryid'];

?>
<table border='2'>
<th>First Name</th>
<th>Order</th>
<?php
echo '<form name="display" method="POST" action="cakephp.php">';
while($row = mysqli_fetch_array($sql))
{
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['order'] . "</td>";
echo '<td><input type="hidden" name="bakeryid" value="' . $bakeryid . '"/></td>';
echo '<td><input type="hidden" name="memid" value="' . $memid . '"/><input type="submit" name="takeorder" value="Take Order" ></td>';
echo "</tr>";
}
echo "</form>";
echo "</table>";

答案:

echo '<td><input type="hidden" name="bakeryid" value="' . $row['bakeryid'] . '"/></td>';

最佳答案

您使用 $_POST['bakeryid'] 设置 $bakeryid,然后使用 $bakeryid 定义 Bakeryid。

请尝试:

$sql = mysqli_query($con,"SELECT `firstname`, `bakeryid`, `order` FROM cakes c INNER JOIN members m ON c.memid = m.memid");

$bakeryid = $_POST['bakeryid']; // this line is unnecessary

?> <table border='2'>
<th>First Name</th>
<th>Order</th>
<?php
echo '<form name="display" method="POST" action="cakephp.php">';
while($row = mysqli_fetch_array($sql))
{
echo "<tr>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['order'] . "</td>";
echo '<td><input type="hidden" name="bakeryid" value="' . $row['bakeryid'] . '"/></td>'; // this line changed
echo '<td><input type="hidden" name="memid" value="' . $memid . '"/><input type="submit" name="takeorder" value="Take Order" ></td>';
echo "</tr>";
}
echo "</form>";

关于php - 为什么这个变量没有被发布并给出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28399862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com