Jump to content

How to find which checkbox(s) selected and get their values ?


htetnainglynn

Recommended Posts

Hi everyone,

 

First time here and learning PHP now. I have a page which includes of several checkboxes based on a table rows. Eg, if my users table has 30 users, there're going to be 30 checkboxes. I am sure you probably hav guessed by now that if the user selected all 30 users, and delete, they all will be deleted in the database. I am having difficulties in how to uniquely identify each checkbox and get the value from each checkbox because I am thinking of storing user_id from the database in each checkbox as value. Any help would be appreciated on this. To my understanding, if one checkbox is selected and i get the value "on" or if there's value in that checkbox i get the value of it in php file but there should be some sort of like arrays to actually loop through the $_POST["inputCheckboxName"] and get selected checkbox's value or something like that ? Any help would be greatly appreciated. Thanks all.

Link to comment
Share on other sites

Umm  I found the answer. It does return as an array and we need to declare the name of the checkbox something like name="checkboxNames[]" and retrieve it back from the php file as array For eg.

 

 

for($i = 0 ; $i < count($_POST(["checkboxNames"]) ; $i++)
{
  //do whatever we wanna do
}

 

Hope it helps others who have the same problem like me.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.