使用PHP复选框阵列GET方法 [英] Using PHP checkbox array with GET Method

查看:199
本文介绍了使用PHP复选框阵列GET方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用PHP 复选框阵列GET方法?
如果有两个复选框点击,这将导致:??some.php参数= 1&安培;参数= 2

你知道,我不习惯写入到数据库中,我刚开始的参数。谢谢你。


解决方案

您需要使用相同的字段名称,然后按 [] 让PHP认识到数组传递复选框

像这样:

 <输入类型=复选框NAME =富[]值=BAR1>
<输入类型=复选框NAME =富[]值=BAR2>
<输入类型=复选框NAME =富[]值=bar3>

所以GET将是:

  phpfile.php富[] = BAR1&放大器;富[] = BAR2和放大器;为foo [] = bar3

如果点击每个复选框。 (POST类似)

请注意,只有被点击复选框将被提交。所以,如果只是 BAR1 BAR2 被点击,那么GET会

<?pre> phpfile.php富[] = BAR1&安培;为foo [] = BAR2

然后就可以通过

访问数组

  $ _ GET [富]

或类似POST

  $ _ POST [富]

希望有所帮助: - )

Can I use PHP checkbox array with the GET Method? And if there are two checkboxes clicked, will that result in: some.php?param=1&param=2 ?

As you know, I am not used to write into database, I'm just getting the parameters. Thanks.

解决方案

You need to pass the checkboxes with the same field name followed by [] so PHP recognizes the array.

Like so:

<input type="checkbox" name="foo[]" value="bar1">
<input type="checkbox" name="foo[]" value="bar2">
<input type="checkbox" name="foo[]" value="bar3">

So the GET would be:

phpfile.php?foo[]=bar1&foo[]=bar2&foo[]=bar3

if every checkbox is clicked. (POST similar)

Please note, that only the clicked checkboxes will be submitted. So, if just bar1 and bar2 are clicked, then the GET would be

phpfile.php?foo[]=bar1&foo[]=bar2

Then you can access that array via

$_GET["foo"]

or similar to POST

$_POST["foo"]

Hope that helps :-)

这篇关于使用PHP复选框阵列GET方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆