store multiple checkbox values in database

here is my insert query

"INSERT INTO regform SET
                                          name = '".$name."',
                                          email = '".$email."',
                                          phone = '".$phone."',
                                          address = '".$address."',
                                          country  = '".$country."',
                                          date_of_birth = '".$dob."',
                                          gender  = '".$gender."',


Want Help here=========>>>>>>>>     hobbies= '".$_JOIN['hobbies']."',

what should i do to store multiple values.
All other things are working but  this i m unable to store multiple  hobbies in data base

                                          favourite_color = '".$favColor."',
                                          degree  = '".$degree."',
                                          username  = '".$u_name."',
                                          password  = '".$pwd."'";




Checkbox value

 <div  class="rightDiv" id="checkboxes">
    <input id="chkbx_0" type="checkbox" name="hobbies[]" value="Games" /> Games
    <input id="chkbx_1" type="checkbox" name="hobbies[]" value="Chatting" />Chatting
    <input id="chkbx_2" type="checkbox" name="hobbies[]" value="Book Reading" />Book Reading
</div>
sil3nt786Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John EastonDirectorCommented:
There are a couple of options I can see.

Firstly, (which may be overkill) is to have a separate table for hobbies and you insert the User, get the users primary key back, then insert into the hobbies table.

Secondly, you could simply save a list of the hobbie ID's.  So if the user selected Games and Book Reading you would save "0,2" in the hobbies field.  This would make it a text or nvarchar field.

Also, a variation of option 2 would be to do something similar using binary code saving 1's or 0's depending on the options selected.  I.e. for the previous example it would be 101 - i.e. the first and last options are 'on'.  This could then be saved as in int value - i.e. this would be 5.  This may be harder to utilise in your script though, although is quite a neat way of saving user options.

Lastly, PHP can serialize an array to save in a database.  This may be the easiest option.  This would require changing your code to something like:
hobbies= '".serialize($_JOIN['hobbies'])."'

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Please see:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_5450-Common-Sense-Examples-Using-Checkboxes-with-HTML-JavaScript-and-PHP.html

You might consider using named hobbies.  You can use PHP var_dump() to see exactly what appears in the $_POST request variables.  A smart design would be a separate table of hobbies.  By listing hobbies in a separate table, you could add or remove hobbies easily.  You can do statistical and trend analysis queries about hobbies (eg: How many people like GAMES, or which hobby was most popular last month).  And you can use a junction table to associate the users and hobbies.
 <div  class="rightDiv" id="checkboxes">
    <input id="chkbx_0" type="checkbox" name="hobbies[GAMES]" value="Games" /> Games
    <input id="chkbx_1" type="checkbox" name="hobbies[CHATTING]" value="Chatting" />Chatting
    <input id="chkbx_2" type="checkbox" name="hobbies[BOOK READING]" value="Book Reading" />Book Reading
</div> 

Open in new window

Vitor MontalvãoMSSQL Senior EngineerCommented:
sil3nt786, do you still need help with this question?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.