title: Mystified by Form Checkboxes
body: <p>I've put together a quiz, with the questions and answers stored in a database. It works for multiple choice questions, and I figured out how to make it work with a fill-in-the-blank question, too.</p>
  
  <p>But I haven't figured checkboxes out yet. I have one question that offers users a choice of five answers, each associated with a checkbox. To get it right, they have to select two of the checkboxes.</p>
  
  <p>I think my problem is with this line in my answer key:</p>
  
  <pre><code> if ($answer10 == "AB") { $totalCorrect++; }
  </code></pre>
  
  <p>For a correct score, a user has to choose the first two checkboxes (values A and B). So AB obviously isn't a right answer, and $answer10 == "A,B" doesn't work, either.</p>
  
  <p>So what's the correct way to tell the answer key the correct choices are A + B?</p>
  
  <p>This is the HTML from a multiple-choice question:</p>
  
  <pre><code>&lt;li id="q9"&gt;
    &lt;div class="Question"&gt;Scientists believe the universe is:&lt;/div&gt;
    &lt;div class="Answer"&gt;
      &lt;label for="q9-A"&gt;
      &lt;div class="Radio"&gt;
        &lt;input type="radio" name="q9" id="q9-A" value="A" style="display: none;"&gt;
        A. disappearing&lt;/div&gt;
      &lt;/label&gt;
    &lt;/div&gt;
    &lt;div class="Answer"&gt;
      &lt;label for="q9-B"&gt;
      &lt;div class="Radio"&gt;
        &lt;input type="radio" name="q9" id="q9-B" value="B" style="display: none;"&gt;
        B. expanding&lt;/div&gt;
      &lt;/label&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>And this is the HTML from my question featuring checkboxes:</p>
  
  <pre><code>&lt;li id="q10"&gt;
    &lt;div class="Question"&gt;Check each item that can be found in our solar system.&lt;/div&gt;
    &lt;div class="Answer" style="margin-top: 5px; background: #000; color: #fff; text-align: center;"&gt;
      &lt;label for="q10-A"&gt;
        &lt;input type="checkbox" name="q10-A" id="q10-A" value="A"&gt;
        planet&lt;/label&gt;
      &lt;label for="q10-B"&gt;
        &lt;input type="checkbox" name="q10-B" id="q10-B" value="B"&gt;
        asteroid&lt;/label&gt;
      &lt;label for="q10-C"&gt;
        &lt;input type="checkbox" name="q10-C" id="q10-C" value="C"&gt;
        black hole&lt;/label&gt;
      &lt;label for="q10-D"&gt;
        &lt;input type="checkbox" name="q10-D" id="q10-D" value="D"&gt;
        neutrino star&lt;/label&gt;
      &lt;label for="q10-E"&gt;
        &lt;input type="checkbox" name="q10-E" id="q10-E" value="E"&gt;
        quasar&lt;/label&gt;
     &lt;/div&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>And this is my answer key:</p>
  
  <pre><code> $answer1 = $_POST['q1'];
   $answer2 = $_POST['q2'];
   $answer3 = $_POST['q3'];
   $answer4 = $_POST['q4'];
   $answer5 = $_POST['q5'];
   $answer6 = $_POST['q6'];
   $answer7 = $_POST['q7'];
   $answer8 = $_POST['q8'];
   $answer9 = $_POST['q9'];
   $answer10 = $_POST['q10'];
   $answer11 = $_POST['q11'];
  
   $totalCorrect = 0;
  
   if ($answer1 == "A") { $totalCorrect++; }
   if ($answer2 == "Jupiter") { $totalCorrect++; }
   if ($answer3 == "C") { $totalCorrect++; }
   if ($answer4 == "D") { $totalCorrect++; }
   if ($answer5 == "A") { $totalCorrect++; }
   if ($answer6 == "C") { $totalCorrect++; }
   if ($answer7 == "C") { $totalCorrect++; }
   if ($answer8 == "B") { $totalCorrect++; }
   if ($answer9 == "B") { $totalCorrect++; }
   if ($answer10 == "AB") { $totalCorrect++; }
   if ($answer11) { $totalCorrect++; }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here's how I plugged Mark M's response into my scoring system:</p>
  
  <pre><code>if (isset($_POST))
    {
      if (isset($_POST['q10-A'], $_POST['q10-B']) &amp;&amp;
          !isset($_POST['q10-C']) &amp;&amp; 
          !isset($_POST['q10-D']) &amp;&amp; 
          !isset($_POST['q10-E'])) 
      {
          $Checkbox = 'A';
      }
  
      else
      {
      $Checkbox = 'B';
      }
  
  }
  
  $answer1 = $_POST['q1'];
  $answer2 = $_POST['q2'];
  $answer3 = $_POST['q3'];
  $answer4 = $_POST['q4'];
  $answer5 = $_POST['q5'];
  $answer6 = $_POST['q6'];
  $answer7 = $_POST['q7'];
  $answer8 = $_POST['q8'];
  $answer9 = $_POST['q9'];
  $answer10 = $Checkbox;
  </code></pre>
  
  <p>The only drawback with this solution is that I have to create a special script for each question that includes checkboxes. So I'll explore the other answers to see if I can find a solution that handles all checkbox questions automatically. Otherwise, this works fine for me. ;)</p>