Php:多个复选框 [英] Php: multiple checkboxes

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

问题描述

我有以下由循环创建的复选框:

I have the following checkbox created by a loop:

<input type='checkbox' value=0 name='<?php echo $question_id; ?>' />

每个复选框都有不同的 ID,当用户选中多个复选框时,我想收集所有 ID 并将其插入到将事件"表与问题"表相关联的表中.

Each checkbox will have a different ID, and when the user checks several checkboxes, I would like to gather all the id's and insert it into a table that relates an 'event' table with a 'questions' table.

但是我没有得到 ids...我知道我应该使用一个数组,但它是在 name 属性中还是在 values 属性中?另外,我如何传递 ID...是否进入值字段?

However I am not getting the ids...I know I am supposed to use an array, but is that in the name attribute or the values attribute? Also, how do I pass on the IDs...does that go into the values field?

推荐答案

在 HTML 中:

<input type='checkbox' value=1 name='checkboxname[<?php echo $question_id; ?>]' />

在 PHP 中:

$set_checkboxes = array_keys($_POST['checkboxname']);

或者:

在 HTML 中:

<input type='checkbox' value="<?php echo $question_id; ?>" name='checkboxname[]' />

在 PHP 中:

$set_checkboxes = $_POST['checkboxname'];

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

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