PHP-插入多个复选框选择的值 [英] php - inserting the values of multiple checkbox selections

查看:96
本文介绍了PHP-插入多个复选框选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要引用的网站是

http://www.iaddesignandstudio.com/offline 选择报价标签

如果一个人要填写此表格并在数字1或数字3中选择一个以上的复选框,我将如何将这些选择的值插入数据库中,以便在检索用户输入或选择的信息时,我可以看看他/她选择了哪个复选框?

if a person where to fill out this form and select more than one checkbox in either number 1 or number 3. how would i insert those selected values into a database so that when i retreive the information the user inputed or selected i can see which checkboxes he/she selected?

推荐答案

提交表单后,可以通过在name属性的末尾添加[]来将复选框设置为位于一个数组中,如下所示:

You can set your checkboxes to be in one array after the form is submitted by adding [] at the end of the name attribute like such:

<input type="checkbox" name="services[]" value="Podcasting Services" /> 
Podcasting Services      
<input type="checkbox" name="services[]" value="Local Search" />Local Search

提交表单后,您的$_POST['services']变量将是一个包含所有检查值的数组.例如:

When the form is submitted, your $_POST['services'] variable will be an array containing all checked values. ex:

#var_dump($_POST['services']);
array(2) {
  [0]=>
  string(19) "Podcasting Services"
  [1]=>
  string(12) "Local Search"
}

然后,您可以执行任何您想做的事情,无论是发送电子邮件还是使用以太币foreach()implode()遍历值到数据库中添加字段.

Then you can do anything you want with that, wether it be sending an email or adding fields to the database using ether foreach() or implode() to loop through the values.

希望这会有所帮助!

这篇关于PHP-插入多个复选框选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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