简体   繁体   中英

Insert into database from array of checkboxes

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

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?

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.
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM