title: Validate user completed form in php/sqlite3
body: <p>I am building a simple quiz in PHP which reads questions from a database and displaying the answer choices as radio inputs. </p>
  
  <p>I want to make sure that the user can only press submit if all the questions have been answered. </p>
  
  <p><code>Validation.php</code> counts the number of correct answers and echoes them. If the user does not answer all the questions and presses submit, then it shows that the user answered all the questions correctly. </p>
  
  <p>I have done this in HTML, but I am not sure how it works considering I am using a while loop to display the questions. The columns in the table <code>quiz</code> are <code>a</code>,<code>b</code>,<code>c</code>, and <code>d</code> for the answer choices, <code>question</code> for the question, and I gave each question an <code>id</code> starting at 1. </p>
  
  <p>I want to make it so that the user has to answer all of the questions before going to the next page. </p>
  
  <p>How do I do this considering I am using a loop?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel="stylesheet" type="text/css" href="css/style_metal.css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  $count = 1;//Number question the user is on
  $db = new PDO('sqlite:project_questions.txt');
  $sql = "select * from quiz";
  $stmt = $db-&gt;prepare($sql);
  $stmt-&gt;execute();
  echo     '&lt;div id="page-wrap"&gt;
          &lt;h1 class="transparent index-headline"&gt;Web Programming Quiz&lt;/h1&gt;
      &lt;form action="validation.php" method="POST" id="quiz"&gt;';
  echo           '&lt;ul id="test-questions"&gt;';
  while($row=$stmt-&gt;fetch()){
   echo          '
                  &lt;li&gt;
                      &lt;div class="quiz-overlay"&gt;&lt;/div&gt;
                      &lt;h3&gt;'.$row['question'].'&lt;/h3&gt;
                      &lt;div class="mtm"&gt;
                          &lt;input type="radio" name='.$row['id'].' id="question-1-answers-A" value="'.$row['a'].'" /&gt;
                          &lt;label for="question-1-answers-A" class="fwrd labela"&gt;'.$row['a'].'&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div&gt;
                          &lt;input type="radio" name='.$row['id'].' id="question-1-answers-B" value="'.$row['b'].'" /&gt;
                          &lt;label for="question-1-answers-B" class="fwrd labelb"&gt;'.$row['b'].'&lt;/label&gt;
                      &lt;/div&gt;';
              if ($row['c'] != 'null'){//for true or false questions
   echo               '&lt;div&gt;
                          &lt;input type="radio" name='.$row['id'].' id="question-1-answers-C" value="'.$row['c'].'"/&gt;
                          &lt;label for="question-1-answers-C" class="fwrd labelc"&gt;'.$row['c'].'&lt;/label&gt;
                      &lt;/div&gt;';
              }
              if ($row['d'] != 'null'){/for true or false questions
   echo               '&lt;div&gt;
                          &lt;input type="radio" name="'.$row['id'].'" id="question-1-answers-D" value="'.$row['d'].'" /&gt;
                          &lt;label for="question-1-answers-D" class="fwrd labeld"&gt;'.$row['d'].'&lt;/label&gt;
                      &lt;/div&gt;';
              }
   echo               '&lt;p class="quiz-progress"&gt;'.$count.' of 25&lt;/p&gt;';
  
     $count++;
  }
  echo               '&lt;/li&gt;
                  &lt;li&gt;
                      &lt;div class="quiz-overlay"&gt;&lt;/div&gt;
                      &lt;h3 class="anticipate"&gt;Now it’s time to see your results...&lt;/h3&gt;
                      &lt;input type="submit" value="Submit Quiz" id="submit-quiz" /&gt;
                  &lt;/li&gt;
                  &lt;/ul&gt;
      &lt;/form&gt;';
  ?&gt;
  
  
  &lt;/body&gt;
  
  
  &lt;/html&gt;
  </code></pre>