【发布时间】:2014-02-02 21:26:20
【问题描述】:
我正在努力解决这个问题。我有一个 foreach 循环:
if(isset($_POST['chkboxes'])) {
foreach($_POST['chkboxes'] as $chkbox) {
echo '- '.$chkbox."<br />";
}
'<input type="hidden" name="options" id="options" value=" ' . $chkbox . '"/>';
echo '<br /><input type="submit" name="button" id="button" value="Confirm"/> </form> </td></tr></table>';
正如您从上面看到的,我尝试在我使用的新 php 页面上隐藏一个值为 $chkbox 的输入:
if(isset($_POST['options'])){
$options = $_POST['options'];
}
我正在尝试在新的 php 页面上显示所有选中的项目,或 $chkbox。另一种形式完美运行,它只是从这个 foreach 循环中获取信息,并尝试让该信息正确显示在新的 php 页面上。
这是我的整个代码的样子:
<?php
require("database.php"); //connect to the database
if(isset($_GET['id'])){
$id = $_GET['id'];
}
$result = mysqli_query($con,"SELECT * FROM menuitem WHERE id='$id' ");
if (!$result) {
printf("Error: %s\n", mysqli_error($con));// Displays the error that mysql will generate if syntax is not correct.
exit();
}
//DYNAMIC PHP PULLING IN THE DATA AND SPITTING OUT THE RESULTS
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$description = $row['description'];
$picturepath = $row['picturepath'];
$name = $row['name'];
$price = $row['price'];
$keywords = $row['keywords'];
$dynamiclist = '<table align="center" width="60%" border="0" cellspacing="5" cellpadding="8">
<tr height="100"></tr>
<tr>
<td width="22%" valign="top" align="left"><img style="border: #66cc33 5px solid;" src="./menupictures/' .$picturepath . '" height="200" width="200" border="1"/></td>
<td width="20%" valign="top" align="left">' . $name . ' <br />$' . $price . '<br /><br />
<td valign="top" align="left"> <form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value=" ' . $id . '"/>';
echo $dynamiclist;
echo "Your Item Options: <br /><br />";
}
if(isset($_POST['chkboxes'])) {
foreach($_POST['chkboxes'] as $chkbox) {
echo '- '.$chkbox."<br />";
'<input type="hidden" name="options[]" id="options" value=" ' . $chkbox . '"/>';
}
echo '<br /><input type="submit" name="button" id="button" value="Confirm"/> </form> </td></tr></table>';
echo' <table width="90%"><tr><td width="30%"></td>
<td width="21%"></td>
<td><font><a href="irohomepage.php">Cancel This Item</a></font></td></tr></table>';
}
mysqli_close($con); //close the db connection
?>
<html>
<body>
</body>
</html>
【问题讨论】:
-
html 是什么样子的?
-
你的问题是为什么它不回显隐藏的输入字段?
-
好吧,我想用 if(isset($_POST['options'])){ $options = $_POST['options']; } 然后在新的 php 页面上,我回显了这些信息。我只需要帮助从复选框中提取这些数据。