Home >Backend Development >PHP Tutorial >How to get the values of all check boxes in a form in PHP, get the check boxes in the form in PHP_PHP tutorial
Generally speaking, only the value of the last checkbox is always obtained in PHP, so how can we obtain the values of all checkboxes?
The solution is as follows:
Part of the code of the 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 code for PHP to process the data passed by POST 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 that what is described in this article has certain reference value for everyone to have a deep understanding of PHP programming.
Yes, the checkbox in the form will not be submitted if there is no selection.
That’s why it is prompted.
==========
You can judge it before outputting it. .
if(isset($_POST["orange"])) echo $_POST["orange"];
Wow, I just did this. The checkbox is an array and you have to put them in the array.
The principle is: pass those values over. Then convert them into non-arrays
For example:
d5430eb23b741835a3a2708ba7d7ec6629
666a14006fd4a81d1e0be6f99eb1a37e30
8589a95ea303841310fff68f536b7c1631
d3d130824c28b8fe16d3baf290ec83b232
These forms
$waistline=$_POST["waistline"];
$myallsport = implode (" ,", $waistline);
In this way, just insert $myallsport into it