Reputation: 25
Hi I have a check box dynamically created as follows;(not the complete code here) there are a number of check boxes created, hence name is an array. (Is it right the way I have started the array inside <td></td>
?)
while ($rec = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td class='tbldecor1'><input type='checkbox' name='delete[]' value='$Val1'></td>";
echo "</tr>";
}
I need to get the user selected check box values to a loop in order to delete the records selected. If I forget about the deleting part of it, to get the user selected values to a loop I used something like below;
$AA = $_POST['delete'];
while($AA == 'checked')
{
echo $AA; // trying to print the user checked options so that I can subsequently code to delete them.
}
but seems an erroneous approach! Can someone please give me an idea?
Upvotes: 0
Views: 64
Reputation: 15981
it's input field array which gives you all checked value into array in $_POST, so use following way
if(isset($_POST['delete'])) {
foreach($_POST['delete'] as $value){
echo $value;
//do stuff
}
}
Upvotes: 0
Reputation: 360702
foreach($_POST['delete'] AS $key => $val) {
...
}
checkboxes which aren't checked in the form aren't submitted, so automatically you'll only get the checked checkboxes in the _POST data.
Upvotes: 2