troubleshooting Question

Storing a PHP Checkbox in a Database

Avatar of meerecat1981
meerecat1981 asked on
8 Comments3 Solutions325 ViewsLast Modified:

I have a PHP page with text and Database fields.

This is the code that draws the checkbox:

    <td width="43"><label for="business_type">Salon</label></td>
    <td width="30"><input type="checkbox" name="business_type[]" id="business_type" value="salon" /></td>
    <td width="38"><label for="business_type">Mobile</label></td>
    <td width="30"><input type="checkbox" name="business_type[]" id="business_type" value="mobile" /></td>
    <td width="53"><label for="business_type">Student</label></td>
    <td width="25"><input type="checkbox" name="business_type[]" id="business_type" value="student" /></td>
    <td width="37"><label for="business_type">Other</label></td>
    <td width="434"><input type="checkbox" name="business_type[]" id="business_type" value="other" /></td>

This is the code that stores the texts fields in the database:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

 mysql_connect("localhost", "web46-training", "training") or die(mysql_error()); 
 mysql_select_db("web46-training") or die(mysql_error()); 
 mysql_query("INSERT INTO `data` VALUES ('$trainee_name', '$company_name', '$address', '$telephone', '$email_address', '$website', '$trainer_name', '$training_date', '$trainer_notes', '$area_consultant')"); 
 Print "Your information has been successfully added to the database."; 

How do I store which of the php checkboxes are checked into the database.  What kind of field do I need to create in the database table.  All my text fields are Varchar.  I was thinking maybe bit?

Many Thanks
Join our community to see this answer!
Unlock 3 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros