Jump to content

Retrieve data from random number of checkboxes


Cep

Recommended Posts

Hello,

I am just wondering if anyone here could tell me how I would collect the post data from my form which has been generated by my PHP script.

Basically my script runs a query to retrieve data from my table and for each row it creates a HTML table row. In the last column of this row I have a checkbox with the value set as that rows primary ID field in the table.

I then want to be able to select any number of these check boxes and submit the form.

As the number of rows generated is random and as the check boxes ticked can be random I need to know how I can get the data into PHP. I have tried naming every checkbox with like this name="myCheck[]" but for some reason I don't get any value at all.

Any help? :)
some code would be good but you can try this

[code]<?php
$i=0;
while($r=mysql_fetch_assoc($res){
echo "<input type=\"checkbox\" name=\"myCheck".$i."\" value=".$r['id'].">
$i++;
}
?>[/code]

then in your script to process the form
[code]<?php
$ids = array();
foreach($_POST as $key => $val){
if(substr($key, 0, 7) == "myCheck"){
$ids[] = $val; 
}
}
?>[/code]

now your id's are in an array called $ids for you to use where ever you like

Ray

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.