title: How can I check value to be inserted in mysql database
body: <p>Please I'm a newbie in php and mysql I want you to help me on how to check if value to be inserted into a database is greater than or lesser than, if greater than it should insert pass, thanks. </p>
  
  <p>this the code</p>
  
  <pre><code>$query="select * from ats_question";
  $rs=mysql_query("select * from ats_question where test_id=$tid",$cn) or  die(mysql_error());
  if(!isset($_SESSION[qn]))
  {
  $_SESSION[qn]=0;
  mysql_query("delete from ats_useranswer where sess_id='" . session_id() ."'") or die(mysql_error());
  $_SESSION[trueans]=0;
  
  }
  else
  {   
          if($submit1=='Next Question' &amp;&amp; isset($ans))
      {
              mysql_data_seek($rs,$_SESSION[qn]);
              $row= mysql_fetch_row($rs); 
  mysql_query("insert into ats_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,
                  true_ans,your_ans)values('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());
              if($ans==$row[7])
              {
                          $_SESSION[trueans]=$_SESSION[trueans]+1;
              }
              $_SESSION[qn]=$_SESSION[qn]+1;
      }
      else if($submit=='Get Result' &amp;&amp; isset($ans))
      {
              mysql_data_seek($rs,$_SESSION[qn]);
              $row= mysql_fetch_row($rs); 
  mysql_query("insert into ats_useranswer(sess_id, test_id, que_des, ans1,ans2,ans3,ans4,true_ans,
      your_ans) values 
  ('".session_id()."', $tid,'$row[2]','$row[3]','$row[4]','$row[5]', '$row[6]','$row[7]','$ans')") or die(mysql_error());
              if($ans==$row[7])
              {
                          $_SESSION[trueans]=$_SESSION[trueans]+1;
              }
              echo "&lt;h1 class=head1&gt; Result&lt;/h1&gt;";
              $_SESSION[qn]=$_SESSION[qn]+1;
              echo "&lt;Table align=center&gt;&lt;tr class=tot&gt;&lt;td&gt;Total Question&lt;td&gt; $_SESSION[qn]";
              echo "&lt;tr class=tans&gt;&lt;td&gt;True Answer&lt;td&gt;".$_SESSION[trueans];
              $w=$_SESSION[qn]-$_SESSION[trueans];
              echo "&lt;tr class=fans&gt;&lt;td&gt;Wrong Answer&lt;td&gt; ". $w;
              echo "&lt;/table&gt;";
              mysql_query("insert into ats_result(login,test_id,grade,score) values
                  ('$login',$tid,grade,$_SESSION[trueans])")
               or die(mysql_error());
              echo "&lt;h1 align=center&gt;&lt;a href=ats_review.php&gt; Review Question&lt;/a&gt; &lt;/h1&gt;";
              unset($_SESSION[qn]);
              unset($_SESSION[sid]);
              unset($_SESSION[tid]);
              unset($_SESSION[trueans]);
              exit;
      }
   }
  $rs=mysql_query("select * from ats_question where test_id=$tid",$cn) or      die(mysql_error());
  if($_SESSION[qn]&gt;mysql_num_rows($rs)-1)
  {
  unset($_SESSION[qn]);
  echo "&lt;h1 class=head1&gt;Some Error  Occured&lt;/h1&gt;";
  session_destroy();
  echo "Please &lt;a href=index.php&gt; Start Again&lt;/a&gt;";
  
  exit;
  }
  mysql_data_seek($rs,$_SESSION[qn]);
  $row= mysql_fetch_row($rs);
  echo "&lt;div align=\"center\" class=\"style2\"&gt;&lt;strong&gt; Ats Examination     &lt;/strong&gt;&lt;/div&gt;";
  echo "&lt;div id=\"\"&gt;&lt;/div&gt;";
  
      echo"&lt;p id=\"note\"&gt;&lt;/p&gt;";
  echo "&lt;form name=myfm id=myfm1 method=post action=ats_exam.php&gt;";
  echo "&lt;table width=100%&gt; &lt;tr&gt; &lt;td width=30&gt;&amp;nbsp;&lt;td&gt; &lt;table border=0&gt;";
  $n=$_SESSION[qn]+1;
  echo "&lt;tR&gt;&lt;td&gt;&lt;span class=style2&gt;Que ".  $n .": $row[2]&lt;/style&gt;";
  echo "&lt;tr&gt;&lt;td class=style6&gt;&lt;input type=radio name=ans value=1&gt;$row[3]";
  echo "&lt;tr&gt;&lt;td class=style6&gt; &lt;input type=radio name=ans value=2&gt;$row[4]";
  echo "&lt;tr&gt;&lt;td class=style6&gt;&lt;input type=radio name=ans value=3&gt;$row[5]";
  echo "&lt;tr&gt;&lt;td class=style6&gt;&lt;input type=radio name=ans value=4&gt;$row[6]";
  
  if($_SESSION[qn]&lt;mysql_num_rows($rs)-1)
  echo "&lt;tr&gt;&lt;td&gt;&lt;input type=submit name=submit1 value='Next Question'&gt;   &lt;/form&gt;";
  
  echo "&lt;tr&gt;&lt;td&gt;&lt;input type=submit name=submit value='Get Result'&gt;&lt;/form&gt;";
  echo "&lt;/table&gt;&lt;/table&gt;";
  ?&gt;
  </code></pre>
  
  <p>i want to check if the trueans is greater than 15 it should insert pass if not fail in the grade value</p>
  
  <pre><code> mysql_query("insert into ats_result(login,test_id,grade,score) values
              ('$login',$tid,grade,$_SESSION[trueans])")
  </code></pre>