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.

[php]<?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”);

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

?>
[/php]

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]

<?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.’
’;
}

?>

[php]

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

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