I have programmatically generated checkboxes based on an array input.
Now based on the checkboxes ticked I was looking around the way in which superglobal variable $_POST can hold those elements, which are actually table values from the database.
I wanted to do some operation here:
if (isset($_POST['download'])) {
foreach ($_POST['download'] as $table) {
echo "Yes"."<br />";
}
}
But this gives error: foreach ($_POST['download'] as $table) {
Warning : Invalid argument supplied for foreach() in /home1/…/pdo_back_up_option.php on line 18
Once the checkboxes are ticked doesn’t the superglobal variable $_POST holds the values in an array?
Something to keep in mind about HTML forms: unchecked boxes aren’t returned. So if I only clicked ‘cars’ and ‘jobs’… the array will only contain two values, instead of the 8 which you may be expecting. One way around this is to prep a default array which blank values for all 8 options, array_merge($form_inputs, $form_default ); This should give you an array with a value for each field that your PDO and then process. Hope that helps