How to add checkbox values into mysql database

I have a checkbox form with 26 different values, I need each value that is checked to be added to the database. I’m not sure how I would go about doing this any help would be greatly appreciated. I’ve been doing various searches/experiments for days now.

$interests = array(“Alumni connections”, “Book club”, “Camping”, “Coffee and conversation”, “Business networking”, “Cooking”, “Dining out”, “Fishing/Hunting”, “Gardening/Landscaping”, “Hobbies and crafts”, “Movies/Videos”, “Museums and art”, “Music and concerts”, “Exploring new areas”, “Nightclubs/Dancing”, “Performing arts”, “Playing cards”, “Playing sports”, “Political interests”, “Religion/Spiritual”, “Shopping/Antiques”, “Travel/Sightseeing”, “Video games”, “Volunteering”, “Watching sports”, “Wine tasting”);

$array = serialize($_POST[‘interests’]);
mysql_query(“INSERT into myTable VALUES(’$array’)”);


You did not post your form here, that would help to give you directions. Here is the code to give you an idea on how to modify your script:

displaying html form:

<?php $interests = array("Alumni connections", "Book club", "Camping", "Coffee and conversation", "Business networking", "Cooking", "Dining out", "Fishing/Hunting", "Gardening/Landscaping", "Hobbies and crafts", "Movies/Videos", "Museums and art", "Music and concerts", "Exploring new areas", "Nightclubs/Dancing", "Performing arts", "Playing cards", "Playing sports", "Political interests", "Religion/Spiritual", "Shopping/Antiques", "Travel/Sightseeing", "Video games", "Volunteering", "Watching sports", "Wine tasting");

foreach($interests as $key=>$val){
echo ’ ‘.$val.’



processing form (save.php):
if($_POST[‘submit’] and is_array($_POST[‘check’])){
mysql_query(“INSERT into myTable VALUES(’”.addslashes($s)."’)"); // saving selected values (comma delimited

If you like to store serialized array, just replace the implode() function in the code above with serialize(), similar to what you have in your code.

Sponsor our Newsletter | Privacy Policy | Terms of Service