hello
hello

Reputation: 81

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?

Upvotes: 0

Views: 1480

Answers (1)

Jasonw
Jasonw

Reputation: 5064

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

Upvotes: 1

Related Questions