views:

1908

answers:

3

the site i'll be refering to is

http://www.iaddesignandstudio.com/offline select the quote tab

if a person where to fill out this form and select more than one checkbox in either number 1 or number 3. how would i insert those selected values into a database so that when i retreive the information the user inputed or selected i can see which checkboxes he/she selected?

+2  A: 

I would have separate fields in the database for them. Like in question 1, the posted form might submit $_POST['admycomp'] and $_POST['provideresource'] as having been checked. If so, insert a 1 into the database field admycomp or provideresource. That way you have recorded which fields they checked.

gaoshan88
+3  A: 

You can set your checkboxes to be in one array after the form is submitted by adding [] at the end of the name attribute like such:

<input type="checkbox" name="services[]" value="Podcasting Services" /> 
Podcasting Services      
<input type="checkbox" name="services[]" value="Local Search" />Local Search

When the form is submitted, your $_POST['services'] variable will be an array containing all checked values. ex:

#var_dump($_POST['services']);
array(2) {
  [0]=>
  string(19) "Podcasting Services"
  [1]=>
  string(12) "Local Search"
}

Then you can do anything you want with that, wether it be sending an email or adding fields to the database using ether foreach() or implode() to loop through the values.

Hope this helps!

smazurov
should i insert it using commas? in one column? so in this case colservices would contain Podcasting Services, Local Search ?
just use implode(', ',$_POST['services']) to get a comma separated list. Note: you will need to check to make sure $_POST['services'] exists or even better is an array already with: if(is_array($_POST['services'])
smazurov
A: 

its right but not full answer.

mohsin