Scratching my head over this one. It should be simple lol

I am passing the values of my checkboxes to an array. I
I then want to put the array in to a foreach loop and then take the id number and removes the records from the database using the foreach loop
(HAVE NOT INCLUDED DB CODE)

However after the passing the values from the checkboxes to the array, it just prints array and goes not further.

Here is my code beloe

<?php 
$id_number = array($_POST['multi_delete']);

foreach ( $id_number AS $a )
{
// Do database delete using id from array
// DELETE * FROM ............ WHERE id=$a;
}
?>
<form method="post" action="">
<input type="checkbox" name="multi_delete[]" value="1">
<input type="checkbox" name="multi_delete[]" value="2">
<input type="checkbox" name="multi_delete[]" value="3">
<input type="checkbox" name="multi_delete[]" value="4">
<input type="submit" name="multi_delete" value="Delete Multiple Items">
</form>

    $POST['mutli_delete'] is already an array, so there's no need to use it with the array() function. In fact there's no reason to assign it to another variable in this case, just do:

    foreach($_POST['multi_delete'] as $a) {
    

      I did try this earlier but kept getting a 500 internal server error as my hosts have turned off error messages in .php

      Anyway after looking at the error log it explained why.
      I just needed a check to see if the variable exists.

      Everything is now working. Thank you very much for the tip.

      Sometimes you need to clarify.

        Write a Reply...