我需要运行这个sql查询,它会给我一个Id和Dates的列表我想点击每个结果,并将Id值带到下一个表单我在上面写了这个查询,但我在debager中看到隐藏的ID得到了他的值,但没有传递到下一个表单我想我的submit()
有问题。我该把他放在哪里?
function ShowAllCarts($user_email) {
$connB = new ProductDAO();
$connB->Connect();
$pro_query = "SELECT * FROM Cart WHERE `Email`='$user_email';";
$db_result = $connB->ExecSQL($pro_query);
$html_result = '<div data-role="content"> <ul data-role="listview" data-theme="b"> ';
$html_result .= '<form action="PreviouscartProduct.php" method="POST"/>';
while($row_array = $db_result->fetch_array(MYSQLI_ASSOC))
{
$Id= $row_array['Id'];
$Date= $row_array['Date'];
//$html_result //
$html_result .="<li><a href='PreviouscartProduct.php'>Cart number: $Id from Date: $Date><input type='hidden' name='Id' value'<?=$Id?>'</input></a></li>'";
$html_result .= '<a onclick="this.form.submit();" </a>;
}
$html_result .= '</form>';
$html_result .= ' </ul> </div>';
$connB->Disconnect();
return $html_result;
}
//display all carts
$func_result = ShowAllCarts($Email);
您需要使用checkbox
元素:
$html_result .="<li>"
."<checkbox name='cartItem[$Id]' value='$Date'>"
. "Cart number: $Id from Date: $Date"
. "</li>'"
;
然后,在PreviouscartTroduct.php中,您可以在cartItem:上迭代
$cartItems = $_POST[ 'cartItem' ];
foreach( $cartItems as $id => $date ) {
... do something ...
}
如果你只想拿一件东西,为什么不使用这个:
$html_result .="<li>"
. "<a href='PreviouscartProduct.php?cartID=$Id&date=$Date'>"
. "Cart number: $Id from Date: $Date"
. "</a>"
. "</li>'"
;
这里面有很多HTML语法错误,请检查验证器中的输出
首先,在.form.submit();之后,打开标记不会关闭;,它应该读取
$html_result .= '<a onclick="this.form.submit();">Anchor Text Here</a>';
编辑:锚元素需要引用表单。给表单元素一个name属性并使用类似的东西
onclick="document.nameattributehere.submit();return false"
在链接上。
结束编辑。
此外,在上面的行中,当您获得输入的value属性时,您已经在使用PHP解析器,因此不需要
<?= and ?>
最后,在同一个标签中,您不需要关闭输入标签
</input>
只需用关闭打开标签
/>
这只是浏览一下,运行验证器以查找其他错误,我相信问题会更清楚。