Home  >  Q&A  >  body text

Form not fetched via POST

$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.

P粉899950720P粉899950720158 days ago326

reply all(1)I'll reply

  • P粉966335669

    P粉9663356692024-04-03 10:38:21

    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.

    ....
          if(isset($_POST['categorien'])){
                echo "pastcategory?";
                if($_POST['categorien'] === $cat['product_category']){
                    $producten = $cat['product_id'];
                    echo "pastcategory!!!!";
                    echo $producten;
                }
            }
         ....

    reply
    0
  • Cancelreply