为什么bakeryid
变量未在我的表单中发布?我收到的错误是
“注意:未定义的变量fabid”
我有两个页面,一个显示表单,第二个是表单的操作。第二种形式一直说它也未定义。 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>';
答案 0 :(得分:0)
$sql = mysqli_query($con,"SELECT `firstname`, `bakeryid`, `order` FROM cakes c INNER JOIN members m ON c.memid = m.memid");
$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>
<td>' . $row['firstname'] . '</td>
<td>' . $row['order'] . '</td>
<td><input type="hidden" name="bakeryid" value="' . $row['bakeryid'] . '"/></td>
<td><input type="hidden" name="memid" value="' . $memid . '"/>
<input type="submit" name="takeorder" value="Take Order" >
</td>
</tr>';
}
echo '</form></table>';
fabid没有出现在表单中的原因是,在设置字段值时,你使用$ bakeryid设置为尚未发生的帖子。您想将值设置为$ row ['bakeryid'],如上所述。
答案 1 :(得分:0)
您使用$bakeryid
设置$_POST['bakeryid']
,但随后使用$bakeryid
定义fabid。
请尝试:
$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>";