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?

3
  • Exact duplicate - stackoverflow.com/questions/242181/… Commented Jan 11, 2009 at 4:04
  • BTW, "1. What is the main purpose of your internet presents ?" Presents should be presence. Commented Jan 11, 2009 at 4:13
  • 1
    While they ask the same question, this is a lot more general and I think merits keeping around. Commented Jan 11, 2009 at 4:17

3 Answers 3

4

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!

Sign up to request clarification or add additional context in comments.

2 Comments

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'])
2

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.

Comments

0

I would suggest storing the values in your database would be to use the SET datatype (eg: http://dev.mysql.com/doc/refman/5.0/en/set.html). This would store each of the checkbox values from a checkbox group in a single column in a storage-efficient way. You would probably need to use implode as mentioned above to create an SQL query to insert your set.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.