$product = '';
$stmt = $verbinding->query("SELECT
product_category, product_id, parent FROM
Productcategory ORDER BY product_category");
$categorien = $stmt->fetchAll();
foreach($categorien as $cats){
if($cats['parent'] === $producten){
echo '<form action="product-list.php" method="post">
<input type="submit" name="cats" value="'. $cats['product_category'] .'"></form>';
echo $producten;
//var_dump($_POST);
if(isset($_POST['cats'])){
echo $_POST['cats'];
echo $cats['product_category'];
echo $cats['product_id'];
if($_POST['cats'] === $cats['product_category']){
$product = $cats['product_id'];
echo $product;
echo "gelukt!!";
}
}
}
}
因此,为了更新我的问题,这段代码可以部分工作,但无法通过 if($_POST['cats'] === $cats['product_id']){ 语句。问题是我的 $_POST['cats'] 只发送任何信息。我不明白为什么。我应该说,虽然我在另一种形式中使用相同的“名称”值,但如果我不这样做,它甚至不会通过 if(isset($_POST['cats'])){ 语句。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
从您的表单中,操作页面是“product-list.php”,它是您处理表单逻辑的同一页面吗?
如果没有,那么您需要在您创建的product-list.php 中编写以下代码。
.... if(isset($_POST['categorien'])){ echo "pastcategory?"; if($_POST['categorien'] === $cat['product_category']){ $producten = $cat['product_id']; echo "pastcategory!!!!"; echo $producten; } } ....