title: Choose correct answer from multiple answers using PHP MySQL?
body: <p>I have this code for examining.</p>
  
  <ul>
  <li>I need to choose the correct answer and give grade for it.</li>
  <li>If the answer was wrong I need to tell the user that he had wrong answer. After that I need to send the grade to another table in my database.</li>
  </ul>
  
  <p>Is there any way that you can hide your true answer because I already posted it  with my code to compare it with the answers.</p>
  
  <pre><code>&lt;?php
  
  function getQuestions()
  {
      require("connection.php");
      $questions = array();
      $query = mysql_query("SELECT * FROM `question` order by id  ") or dir(mysql_error());
      if (mysql_num_rows($query) &gt; 0) {
      while ($fetch = mysql_fetch_assoc($query)) {
          $questions['questions'] = $fetch;
          if (!empty($questions)) {
          echo "&lt;table width='100%'&gt;";
          foreach ($questions as $qstn)
              echo "&lt;hr size='2%'&gt;"; {
              echo "&lt;tr&gt;&lt;td&gt;" . $qstn["question"] . "&lt;/td&gt;&lt;/tr&gt;";
              echo "&lt;tr&gt;&lt;td&gt;&lt;input type='radio'  name='ans1' required='required' title='Please Answer the Questions'&gt;" . $qstn["ans1"] . "&lt;/td&gt;&lt;/tr&gt;";
              echo "&lt;tr&gt;&lt;td&gt;&lt;input type='radio' name='ans2' required='required' title='Please Answer the Questions'&gt;" . $qstn["ans2"] . "&lt;/td&gt;&lt;/tr&gt;";
              echo "&lt;tr&gt;&lt;td&gt;&lt;input type='radio' name='ans3' required='required' title='Please Answer the Questions'&gt;" . $qstn["ans3"] . "&lt;/td&gt;&lt;/tr&gt;";
              "&lt;tr&gt;&lt;td&gt;&lt;input type='hidden' name='TrueAns'&gt;" . $qstn["TrueAns"] . "&lt;/td&gt;&lt;/tr&gt;";
          }
          echo "&lt;/table&gt;";
          }
      }
      }
      return $questions;
  }
  
  getQuestions();
  
  $submit  = $_POST['submit'];
  $ans1    = $_POST['ans1'];
  $ans2    = $_POST['ans2'];
  $ans3    = $_POST['ans3'];
  $TrueAns = $_POST['TrueAns'];
  if ('ans1' == 'TrueAns') {
      echo "correct answer";
  } else {
      echo "wrong answer";
  }
  if ('ans2' == 'TrueAns') {
      echo "correct answer";
  } else {
      echo "wrong answer";
  }
  if ('ans3' == 'TrueAns') {
      echo "correct answer";
  } else {
      echo "wrong answer";
  }
  ?&gt; 
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;meta http-equiv="content-type" content="text/html" /&gt;
      &lt;meta name="author" content="MOHAMMED" /&gt;
      &lt;title&gt;Question&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form action="test.php" method="POST"&gt;
        &lt;button type="submit" value="answer"&gt;submit your answer&lt;/button&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>