search
Homephp教程php手册PHP获取表单所有复选框的值的方法,php获取表单复选框

PHP获取表单所有复选框的值的方法,php获取表单复选框

通常来说,php中总是只获取最后一个复选框的值,那么如何才能获取所有复选框的值?

解决办法如下:

form表单的部分代码如下:

<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

php处理POST传递过来数据的代码如下:

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

相信本文所述对大家深入掌握PHP程序设计有一定的借鉴价值。

PHP 表单问题 怎获取复选框数据

对,没选择的情况下,表单中的checkbox是不会提交的.
所以就提示了.
=========
你可以判断一下再输出.
if(isset($_POST["orange"])) echo $_POST["orange"];
 

php form表单怎post获取checkbox值,放入到数据库里?

哇,我刚做这个,checkbox是数组你要把他们放在数组里面
原理就是:把那几个值传过来。再把他们转成非数组
比如:
29
30
31
32
这几个表单
$waistline=$_POST["waistline"];
$myallsport = implode (",", $waistline);

这样insert的时候 就把$myallsport 这个插入到里面就O了
 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor