PHP is used to obtain the values of all the check boxes of a form. php is used to obtain the check boxes of a form.
Generally, php always obtains only the value of the last check box. How can we get the value of all check boxes?
The solution is as follows:
Some code of form is as follows:
<input type="checkbox" name="frm_tag[]" value="1">1<input type="checkbox" name="frm_tag[]" value="2">2<input type="checkbox" name="frm_tag[]" value="3">3<input type="checkbox" name="frm_tag[]" value="4">4<input type="checkbox" name="frm_tag[]" value="5">5
The php code for processing POST-transmitted data is as follows:
$str_tag = "";$frm_tag = $_POST['frm_tag'];for($i=0;$i<count($frm_tag);$i++){ echo $frm_tag[$i]."<br>"; if($i==0) $str_tag = $frm_tag[$i]; else $str_tag = $str_tag.",".$frm_tag[$i];}echo $str_tag;}
I believe this article provides some reference value for you to have a deep understanding of PHP programming.
How to obtain check box data for PHP form Problems
Yes. If no selection is made, the checkbox in the form will not be submitted.
So the prompt is displayed.
==========
You can judge and output again.
If (isset ($ _ POST ["orange"]) echo $ _ POST ["orange"];
How can I post a php form to get the checkbox value and put it into the database?
Wow, I just did this. checkbox is an array. You need to put them in the array.
The principle is: pass those values. Convert them into non-arrays.
For example:
<Input type = "checkbox" name = "waistline []" value = "29"/> 29
<Input type = "checkbox" name = "waistline []" value = "30"/> 30
<Input type = "checkbox" name = "waistline []" value = "31"/> 31
<Input type = "checkbox" name = "waistline []" value = "32"/> 32
These forms
$ Waistline = $ _ POST ["waistline"];
$ Myallsport = implode (",", $ waistline );
In this way, $ myallsport will be inserted into the insert file.