title: php quiz undefined offset error
body: <pre><code> &lt;?php
      $connection=mysql_connect('localhost','root',"");
      if(!$connection)
      {
          die("database connection failed".mysql_error());
      }
      $db_select=mysql_select_db("db",$connection);
      if(!$db_select)
      {
          die("database connection failed".mysql_error());
      }
      if(!isset($_POST['submit']))
      {
          echo "&lt;form method=\"post\" action=\"test1.php\"&gt;";
          $sub_result=mysql_query("SELECT * from test where tid='1' order by rand() limit 0,2",$connection);
          if(!$sub_result)
          {
              die("database query failed". mysql_error());
          }
  
          while ($sub_row=mysql_fetch_array($sub_result))
          {
              $id=$sub_row["qno"];
              $ques=$sub_row["ques"];
              $opt1=$sub_row["opt1"];
              $opt2=$sub_row["opt2"];
              $opt3=$sub_row["opt3"];
              $opt4=$sub_row["opt4"];
              $ans=$sub_row["ans"];
  
              echo "&lt;h3&gt;Q".$id." :".$ques."&lt;/br&gt;&lt;/h3&gt;";   
              echo"&lt;/br&gt;
                  $opt1
                  &lt;input type= radio name=\"{$id}\" value=\"{$opt1}\" &gt;
                  &lt;/br&gt;
                  $opt2
                  &lt;input type= radio name=\"{$id}\" value=\"{$opt2}\"&gt;
                  &lt;/br&gt;
                  $opt3
                  &lt;input type= radio name=\"{$id}\" value=\"{$opt3}\"&gt;
                  &lt;/br&gt;
                  $opt4
                  &lt;input type= radio name=\"{$id}\" value=\"{$opt4}\"&gt;
                  &lt;/br&gt;&lt;/br&gt;";
          }
          echo"&lt;input type='submit' value='see how you did it' name='submit'&gt;";
          echo"&lt;/form&gt;";
  
      }
  
  
          if(isset($_POST['submit']))
          {
  
          $total=0;
          $answer=mysql_query("select qno,ans from test",$connection);
  
          while($ans=mysql_fetch_assoc($answer))
          {
              if($_POST[$ans['qno']] === $ans['ans'])
              {
                  $total++;
              }
              else
              {
              }
          }
          echo"&lt;p align=center&gt;&lt;b&gt;I Got $total&lt;/b&gt;";
          }
   ?&gt;
  </code></pre>
  
  <p><strong>Error coming "UNDEFINED OFFSET in line 60, where I am validating the answer."</strong></p>