I have a list of checkboxes that I want to insert into a database, which I have processed as an array:
<input name="my_array[]" value="<?php echo $data['ID'] ?>" type="checkbox">
<?php echo $data['name'] ?><?php echo "br/>";
I'm getting my list of checkboxes from my database, and the selected checkboxes are being posted like so:
$strFoo=$_POST['my_array'];
$strBar = "";
foreach ($strFoo as $strFooName) {
$strBar .= $strFooName . ", ";
}
$strBar = substr($strBar, 0, -2);
Echoing, I get my list of ID's selected like so 1, 2, 3, 4
My below foreach is unfortunately only inserting the first ID of the array only..
foreach ($strFoo as $strFooName) {
$strSql="INSERT INTO table (ID)
VALUES ('$strBar')";
}
How can I insert each ID into my table?