I have a few checkboxes that i want to insert their values into a database if they are checked.
HTML:
<input type="checkbox" id="m1" name="category[]" value="1"/>
<input type="checkbox" id="m2" name="category[]" value="2"/>
<input type="checkbox" id="m3" name="category[]" value="3"/>
<input type="checkbox" id="m4" name="category[]" value="4"/>
<input type="checkbox" id="m5" name="category[]" value="5"/>
I can print out the category array fine and it gives me the correct values according to which checkboxes i clicked. I just can't seem to loop through them to insert multiple rows in my database.
After inserting into database the database should look like this:
| USERID | MACHINEID |
----------------------
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
If i only click the first 3 checkboxes.
I was thinking something like this:
$array_zone = $_POST['category'];
if(isset($_POST['category']))
{
for($i = 0; $i < count($array_zone); $i++)
{
mysql_query("INSERT INTO `userPlanDetail` (`user_id`, `machine_id`) VALUES ('$user_id', ' $array_zone[$i]')");
}
}