我的表格看起来像这样:
$dynamiclist = '<table align="center" width="60%" border="0" cellspacing="5" cellpadding="8">
<tr height="20"></tr>
<tr>
<td width="70%" valign="top" align="left"> <br />' . $name . ' <br /><br />$' . $price . '<br /><br />
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value=" ' . $id . '"/>';
echo $dynamiclist;
$i=0;
foreach(explode(',', $keywords) as $keyword) {
$keyword = trim($keyword);
$chkname = "checkbox{$i}";
$i = $i+1;
echo '<input type="checkbox" name="chkboxes[]" value="'.$keyword.'" id="chk_'.$keyword.'" /><label for="chk_'.$keyword.'">'.$keyword.'</label>'."<br />\r\n";
}
echo '<input type="submit" name="button" id="button" value="Add to Order"/> </form> </td></tr></table>';
}
如上所示,我有一个名为“pid”的隐藏字段,从我的数据库中提取项目的ID,然后我还有一个带有名称复选框的输入类型复选框。
我遇到的问题是我无法同时在新页面上显示这两个数据。
if(isset($_POST['chkboxes'])) {
foreach($_POST['chkboxes'] as $chkbox) {
echo 'Checkbox checked: '.$chkbox."<br />\r\n";
}
}
if(isset($_POST['pid'])){
$pid = $_POST['pid'];
$wasfound = false;
$i = 0;
//if the cart session variable is not set or cart array is empty
if(!isset($_SESSION["cart_array"]) or count($_SESSION["cart_array"]) < 1){
//Run if the cart is empty or not set
$_SESSION["cart_array"] = array(1 => array("item_id" => $pid, "quantity" => 1));
//establishing the cart_array variable in a session/multidimesional array -- database id assoc $pid from pid in form.
}else {
array_push($_SESSION["cart_array"], array("item_id"=> $pid, "quantity" => 1 ));
}
header("location: cart.php");
exit();
}//close if condition
我尝试删除the $_POST['pid']
信息,然后显示$_POST ['chkboxes']
数据。有任何想法吗?我会选择正确的答案。谢谢!