jeudi 3 janvier 2019

PHP Form Selected getting all values

<?php
if(isset($_POST['feature'])){
  if(isset($_POST['test'])){
    foreach($_POST['test'] as $selected){
    $option = 'No';
    var_dump($row['product_id']);
    }
    }
  }

 ?>



<form action="" method="POST">
<?php
$query = $products->findAll();
 foreach($query as $row){
   if($row['featured'] == 'Yes'){
     echo "<label for='featured'>" . $row['p_name'] . " </label> <input type='checkbox' name='test[]' value ='Yes'checked>
     <input type='hidden' name='product_id' value='" . $row['product_id'] . "'>";
   }
   else
   {
   echo "<label for='featured'>" . $row['p_name'] . " </label> <input type='checkbox' name='test[]' value ='No'>
   <input type='hidden' name='product_id' value='" . $row['product_id'] . "'>";
}
}
 ?>
 <input type="submit" name="feature" value="Feature">

 </form>

Can anyone help me understand when I var_dump the product id's I get an array of the last id and not all of them individually? It's cycling through all that is selected so should return the id value for each of them?




Aucun commentaire:

Enregistrer un commentaire