Page 1 of 1

Multiple selections into database column

Posted: Sun Mar 13, 2016 2:26 pm
by karyoker
With multiple boxes and more than one selected, how does one put the checked boxes into an array and insert into a single database column? Any links or videos would be appreciated.
For example:

Code: Select all

<tr>
    <td><label>
      <input type="checkbox" name="social" value="facebook" id="social_0">
      Facebook</label></td>
  </tr>
  <tr>
    <td><label>
      <input type="checkbox" name="social" value="twitter" id="social_1">
      Twitter</label></td>
  </tr>
  <tr>
    <td><label>
      <input type="checkbox" name="social" value="other" id="social_2">
      Other</label></td>
  </tr>
  <tr>
    <td><label>
      <input type="checkbox" name="social" value="fiended" id="social_3">
      I have friended him</label></td>
  </tr>

Re: Multiple selections into database column

Posted: Sun Mar 13, 2016 8:27 pm
by Christopher
Try:

Code: Select all

      <input type="checkbox" name="social[]" value="facebook" id="social_0">
OR
      <input type="checkbox" name="social[facebook]" value="1" id="social_0">

Re: Multiple selections into database column

Posted: Mon Mar 14, 2016 6:48 am
by Celauran
karyoker wrote:With multiple boxes and more than one selected, how does one put the checked boxes into an array and insert into a single database column?
Ideally one doesn't. Keep your database normalized.

Re: Multiple selections into database column

Posted: Mon Mar 14, 2016 5:47 pm
by Christopher
Although strangely, they did say "single database column" which could mean putting values in a column in multiple rows, like a table with just an autoincrement id and a social column. Honestly I only read up until "how does one put the checked boxes into an array" and figured I'd answer that first. ;)