troubleshooting Question

Storing a PHP Checkbox in a Database

Avatar of meerecat1981
meerecat1981 asked on
PHPMySQL Server
8 Comments3 Solutions325 ViewsLast Modified:
Hello

I have a PHP page with text and Database fields.

This is the code that draws the checkbox:

<tr>
    <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>
  </tr>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<? 
 $trainee_name=$_POST['trainee_name']; 
 $company_name=$_POST['company_name']; 
 $address=$_POST['address']; 
  $telephone=$_POST['telephone']; 
 $email_address=$_POST['email_address']; 
 $website=$_POST['website'];
  $trainer_name=$_POST['trainer_name']; 
 $training_date=$_POST['training_date']; 
 $trainer_notes=$_POST['trainer_notes'];
 $area_consultant=$_POST['area_consultant'];
 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."; 
 ?> 
</body>
</html>

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
ASKER CERTIFIED SOLUTION
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