Question

I am creating a set of checkboxes dynamically using PHP based on the value from databases.My requirement is to get the ID of the checked checkboxes and pass it to the next page when user clicks the submit button via POST.I am not using AJAX.

For example I need something like this

first page:

<input type="checkbox" name="check[]" id="checkme<?php echo var; ?>">.......

secondpage.php:

$getcheckboxID = $_POST['check[]']
Was it helpful?

Solution 2

use the below change the $userid to whatever the variable is that has the id. This depends on how your creating the dynamic checkbox. When you pull the data from the database you need a while loop to display the data inside the form tag.

... more code should be here like connection and db selection
$query = "your query here";

while( $input = mysql_fetch_assoc( $quer) )
{
echo "<input type=\"checkbox\" name=\"id[]\" value=\"$input['your_id_column_here']\" />";
}

sample of the input

<input type="checkbox" name="id[]" value="$userid" />

then just loop over it

if( isset( $_POST['id'] ) ) // only if post data is there
{

$ids = $_POST['id'];

foreach($ids as $id)
{

// remove from db or whatever you want to here

}

}

OTHER TIPS

Form controls submit their name and value to the server, not their id (that's for client side use only). If, as in your example, they have no value then they cannot be successful and won't submit anything.

Store the data you are after in the value.

PHP also parses a name like check[] into an array called check, so you need to loop over $_POST['check'] and not try to access $_POST['check[]']

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top