从复选框数组插入数据库

时间:2022-03-08 09:40:10

i have a form that contains checkboxes. I've named the checkboxes as stream[], so it's an array of checkboxes.

我有一个包含复选框的表单。我将复选框命名为stream [],因此它是一个复选框数组。

I would like to insert the checkbox values if it is checked.

如果选中复选框值,我想插入复选框值。

<p><input type="checkbox" name="stream[]" value="survey" id="svy"/>Survey</p>
                <p><input type="checkbox" name="stream[]" value="write_review" id="wr">Write Review</p>
                <p><input type="checkbox" name="stream[]" value="fb post" id="fbp">Facebook Post</p>.

How do i do that?

我怎么做?

1 个解决方案

#1


1  

should not be that difficult, check out this link and this. But the essential idea is to know the right way to access the checkbox. Below is the general idea, a little homework for you to do the necessary changes to the code below to suit your situation.

不应该那么难,看看这个链接和这个。但基本的想法是知道访问复选框的正确方法。以下是一般性的想法,一些功课,你可以根据自己的情况对下面的代码进行必要的修改。

$streams = $_POST['stream'];
foreach ($streams as $stream) {
  if ($stream == $value)
  {
     // checked value.
  }
}

#1


1  

should not be that difficult, check out this link and this. But the essential idea is to know the right way to access the checkbox. Below is the general idea, a little homework for you to do the necessary changes to the code below to suit your situation.

不应该那么难,看看这个链接和这个。但基本的想法是知道访问复选框的正确方法。以下是一般性的想法,一些功课,你可以根据自己的情况对下面的代码进行必要的修改。

$streams = $_POST['stream'];
foreach ($streams as $stream) {
  if ($stream == $value)
  {
     // checked value.
  }
}