title: How to check which option was selected in foreach loop PHP
body: <pre><code>&lt;?php
        require_once(&quot;SQLSrvConnect.php&quot;);
        $producten = '';
        
        //Get the headings from the database
        try{
          #$data = $verbinding-&gt;query(&quot;SELECT product_category, product_id FROM Productcategory WHERE Parent = '$rubriek' ORDER BY product_category&quot;);
          $data = $verbinding-&gt;query(&quot;SELECT product_category, product_id, parent FROM Productcategory ORDER BY product_category&quot;);
  
          # haal alle gegevens in 1 keer uit de database
          $categories = $data-&gt;fetchAll();
          
          foreach($categories as $cat) {
            if ($cat[&quot;parent&quot;] === &quot;-1&quot;){
              echo '&lt;form action=&quot;product-list.php&quot; method=&quot;post&quot;&gt;
              &lt;input type=&quot;submit&quot; name=&quot;categorien&quot; value=&quot;'. $cat['product_category'] .'&quot;&gt;&lt;/form&gt;';
              echo $cat['product_id'];
              //echo '&lt;a class=&quot;dropdown-item&quot; href=&quot;product-list.php?page=overzicht&amp;category='.$cat[&quot;product_id&quot;].'&quot;&gt;'.$cat['product_category'].'&lt;/a&gt;';
              
          }
        }
        if($_SERVER['REQUEST_METHOD'] === 'POST'){
             echo $cat['product_id'];
          if(isset($_POST['categorien'])){
            
            $producten = $cat['product_id'];
          }
          // $producten = $cat['product_id'];
          // $parent = $cat['parent'];
        }
      }
        
        catch (PDOException $e){
          echo &quot;Kan rubrieken niet laden&quot;;
        }
        ?&gt;
  
  </code></pre>
  <p>Hello everyone, I have a list of rubrics that I am loading in her by using a foreach loop to get them from my database. I do have one question here though, how can I check whether the rubric was selected with the If statement so that I will be able to save that rubrics id. I cannot seem to be able to fix it. I would appreciate if someone could help me out. And my $cat['product_id'] is always 107706 when I echo it.</p>