Jump to content

[SOLVED] Store all selected checkbox ids


deezy

Recommended Posts

Hello

 

I have a repeating table with a checkbox at the end of each row. The checkboxes are dynamically assigned a different name:

 

<input type="checkbox" name="checkbox" id="<? echo $row_details['id']; ?>" value="<? echo $row_details['id']; ?>"

 

Upon submission of the form how can i go through the checkboxes and for each checked item i need to order them like (id1,id3,id7,id9) and store the whole string into my database?

 

thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/107552-solved-store-all-selected-checkbox-ids/
Share on other sites

The HTML should be like this

<input type="checkbox" name="checked[]" id="<? echo $row_details['id']; ?>" value="<? echo $row_details['id']; ?>"

 

I changed the name to checked[]. That will be the array all the ID's are stored in.

 

Now to get all the values, just use a foreach loop:

 

<?php

foreach ($_POST['checked'] as $id){
   echo $id.'<br>';
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.