如何在 PHP 中获取复选框值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10632490/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 22:40:01  来源:igfitidea点击:

How to GET checkbox values in PHP

phphtmlformscheckbox

提问by Cooly Wizardy

Possible Duplicate:
Retrieving values from a checkbox

可能的重复:
从复选框中检索值

In the following script I am able to return only the last selected value of the checkbox. How do I return the rest of the values for validation purpose.

在以下脚本中,我只能返回复选框的最后一个选定值。如何返回其余值以进行验证。

HTML Form

HTML 表单

Qualification: <input type="checkbox" name="qual" value="10" /> 10th Std
<input type="checkbox" name="qual" value="12" /> 12th Std
<input type="checkbox" name="qual" value="grad" /> Graduation

PHP Code

PHP代码

 $qual = array();
 $qual = $_GET['qual'];

 print_r ($qual);

回答by Kichu

Try this one .This may help you ....

试试这个。这可能会帮助你......

<input type="checkbox" name="qual[]" value="10" /> 10th Std
<input type="checkbox" name="qual[]" value="12" /> 12th Std
<input type="checkbox" name="qual[]" value="grad" /> Graduation

PHP Coding:

PHP编码:

$qualfication = $_GET['qual'];
print_r($qualfication);

回答by raina77ow

Try changing the names of checkbox inputs to qual[], like this:

尝试将复选框输入的名称更改为qual[],如下所示:

<input type="checkbox" name="qual[]" value="10" /> 10th Std
<input type="checkbox" name="qual[]" value="12" /> 12th Std
<input type="checkbox" name="qual[]" value="grad" /> Graduation

回答by Rick Kuipers

Change name="qual"into name="qual[]"

更改name="qual"name="qual[]"

This will give you an array:

这会给你一个数组:

$qual = $_GET['qual'];
print_r($qual);