Faced a problem: I can not correctly write the removal code for a row in the table via the checkbox .
The algorithm is as follows: I select the checkbox in the row, then click on the "delete" button and the record is deleted from the table.
The code for the checkbox is as follows:
in line

 <td><input type="checkbox" name="abs[]" value="<?=$items[$key]['id'] ?>"></td> 

I create a checkbox array called abs , in value I assigned php code that defines the id string to know which line to remove.
Here is the code that I wrote, it does not work. Tell me how to properly make the row in the table deleted.
I have the following check: if there is an abs(checkbox) array and the argys button is argys , then the condition is met.
I have done everything on PDO php, and I do not understand how to change the request under the checkbox .

 if(isset($_POST['argys']) and (isset($_POST['abs']))) { $id=$_POST['id']; $result=$dbh->prepare("DELETE FROM `Oke`.`tovars` WHERE `tovars`.`id` = :id;"); $result->bindParam(':id', $id); $result->execute(); } 
  • array checkbox $ _POST ['abs'] I saved in the session. - Eliot
  • the row in the table looks like this <td> <input type = "checkbox" name = "abs []" value = "<? = $ items [$ key] ['id']?>"> </ td> - Eliot
  • Please show JS code and HTML. still make sure you have arrays. print_r ('<pre>'); print_r ($ _ POST); print_r ('</ pre>'); or var_dump ('<pre>', $ _ POST, '</ pre>'); - Raaur

2 answers 2

you make an invisible field <input type="hidden" name = deletedID value= $id /> then put the checkbox <input type="checkbox" name="abs" /> all.

 <form action="delete.php" > <input type="hidden" name = deletedID value= $id /> <input type="checkbox" name="abs" /> <input type="submit" /> </form> if(isset($_POST['deletedID ']) and (isset($_POST['abs'])) and $_POST['abs']=='on') 

{

 $id=$_POST['deletedID ']; $result=$dbh->prepare("DELETE FROM `Oke`.`tovars` WHERE `tovars`.`id` = :id;"); $result->bindParam(':id', $id); $result->execute(); 

}

    Here is the solution to my question, checked works perfectly.

     $bigimage = $_POST['checkbox']; $stmt = $dbh->prepare("DELETE FROM imagegallery WHERE id = :id"); // ^ named placeholder foreach ($bigimage as $id) { $stmt->execute(array(':id' => $id)); // ^ put an key value pair array inside with the // designated named placeholder along with the value }