Multiple selections into database column

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
karyoker
Forum Newbie
Posts: 3
Joined: Thu Feb 18, 2016 6:42 pm

Multiple selections into database column

Post 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>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Multiple selections into database column

Post 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">
(#10850)
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Multiple selections into database column

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Multiple selections into database column

Post 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. ;)
(#10850)
Post Reply