Save each row in an array when submitting a form

1

I'm doing a form that takes information from a mysql database and php shows it in a form with checkboxes, my question is this:

How do I save each selected row in an array?

This is the code that creates each row of the form:

while($row = mysqli_fetch_array($result))
{
  echo "<tr>";
  echo "<td>" . $row['ID'] . "</td>";
  echo "<td>" . $row['producto'] . "</td>";
  echo "<td>" . $row['precio'] . "</td>";
  echo "<td><input type='checkbox' name='name". $row['ID'] ."' value=". $row['ID'] ."></td>"; 
  echo "</tr>";
}
echo "</table>";
echo "<input type='submit' name='enviar' value='enviar'>";
echo "</form>"; '
    
asked by Sebastian 03.08.2016 в 02:25
source

1 answer

1

You can name the checkbox as an arrangement

echo "<td><input type='checkbox' name='name[]'introducir el código aquí'". $row['ID'] ."' value=". $row['ID'] ."></td>"; 

and in your php file where you process the information you will receive an arrangement with all the selected checkboxes

 $datos = $_POST["name"];

foreach($datos as $selected){
    echo $selected."</br>";
}
    
answered by 03.08.2016 в 20:01