$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!!"; } } } }
So, to update my question, this code works partially, but not with the if($_POST['cats'] === $cats['product_id']){ statement. The problem is that my $_POST['cats'] just sends no information. I do not understand why. I should say that although I'm using the same "name" value in another form, if I don't do that it won't even pass the if(isset($_POST['cats'])){ statement.
From your form, the action page is "product-list.php", is it the same page where you handle the form logic?
If not, then you need to write the following code in the product-list.php you created.