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

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
Release: 2016-07-13 10:19:53
Original
1009 people have browsed it

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

Copy after login

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;
}

Copy after login

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:
29
30
31
32
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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template