Welcome to the OzoneAsylum FaqWiki
Frequently Asked Questions
Server Side Coding
PHP

How do I pass data from checkboxes in a form using PHP? Pages that link to <a href="https://ozoneasylum.com/backlink?for=5364" title="Pages that link to How do I pass data from checkboxes in a form using PHP?" rel="nofollow" >How do I pass data from checkboxes in a form using PHP?\

The trick is to make the name of the checkbox an array:

code:
<input type="checkbox" name="my_check&#91;1&#93;" /> 1<br />
<input type="checkbox" name="my_check&#91;2&#93;" /> 2<br />
ETC.



and then process it on the page you send the data to like:

code:
if (is_array ($my_check)) {

while (list ($key, $value) = each ($my_check)) {
$data .= "$key, ";
}

}



Adapt the name and who you want the data outputted and you'll be away.

---------------------
Note:

You can also set the values this way too (I'm not aware of any differences in performance between the 2 methods):

code:
<input type="checkbox" name="my_check&#91;&#93;" value="1" /> 1<br />
<input type="checkbox" name="my_check&#91;&#93;" value="2" /> 2<br />
ETC.



_________________________
Emperor

(Added by: Emperor on Wed 23-Oct-2002)

(Edited by: Emperor on Fri 25-Oct-2002)

« BackwardsOnwards »

Show Forum Drop Down Menu