I have multiple checkboxes (don't know how much, will print dynamically). I am using the following code to check how much boxes are selected.
<form action="#" method="post">
<input type="checkbox" name="check_list[]" value="C/C++"><label>C/C++</label><br/>
<input type="checkbox" name="check_list[]" value="Java"><label>Java</label><br/>
<input type="checkbox" name="check_list[]" value="PHP"><label>PHP</label><br/>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
include ("include/connection.php");
if(isset($_POST['submit']))
{
if(!empty($_POST['check_list']))
{
foreach($_POST['check_list'] as $selected)
{
$query = mysqli_query($db, "INSERT INTO table (field) VALUES ('$selected')");
if($query)
{
echo "Query done for ". $selected . "<br>";
}
else
{
echo "problem". mysqli_error();
}
}
}
}
?>
Now the question is I want to run a query on each one by one. How can I do it in PHP? using while loop, for loop or anyother method?