Home  >  Article  >  Backend Development  >  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

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

WBOY
WBOYOriginal
2016-07-13 10:19:53995browse

PHP method to get the values ​​of all checkboxes in the form, php to get the form checkboxes

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.

PHP form problem How to get checkbox data

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"];

How to post the php form to get the checkbox value and put it into the database?

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/871102.htmlTechArticlePHP method to get the values ​​​​of all check boxes in the form, php gets the form check box. Generally speaking, in php Always only get the value of the last checkbox, so how can I get the value of all checkboxes...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn