title: Online quiz system using php and sql session
body: <p>I am currently working on a online quiz system which stores the value user answers in the database  but only the marks and not the questions .On quiz page one question is selected among 10 question using random function of php .i am creating sessions for user login each time and storing variable in session variable..please help as am new to this web world ..</p>
  
  <p>I face the following problems as :-</p>
  
  <p>1-Now whenever i try to store the the answer in database it is incremented once and if refresh  the page it again increments once and this ay the times i refresh ..which is disgracefull is there any way to avoid this and increase marks coloumn of user only once.</p>
  
  <p>2.The second thing is that how i can select next question in quiz page i.e selecting one 1/10 question each time without refreshing page and simultaneously hiding other questions like we do in quiz system using php without using random function </p>
  
  <p>My code is--using 4 questions on page-</p>
  
  <pre><code>&lt;?php
  session_start();
  $username=$_SESSION['username'];
  $total=$_SESSION['total'];
  $q1=isset($_POST['q1']);
  $q2=isset($_POST['q2']);
  $q3=isset($_POST['q3']);
  $q4=isset($_POST['q4']);
  $q5=isset($_POST['q5']);
  $full=30;
  echo 'Welcome '.$username;
  echo $total;
  
  function quiz(){
  $set=rand(1,5);
  $total=0;
  
  echo $set;
   switch($set)
   {
  
   case 1:
  
   echo '&lt;form action="quiz.php" method="post" align="center"&gt;
  &lt;table align="center"&gt;
  &lt;tr&gt;&lt;label name="question" id="ques"&gt;&lt;h1 &gt;ISM stands for?&lt;/h1&gt;&lt;/label&gt;&lt;tr&gt;
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q1" value="A"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Mines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q1" value="B"&gt;&lt;/td&gt;
  &lt;td &gt;Indian Science Of Mines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q1" value="C"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Mineral&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr &gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q1" value="D"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Machines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr &gt;
  
  
  &lt;td align="center"&gt;&lt;br&gt;&lt;input type="submit" name="snext" value="Save/Next"&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/form&gt;';
  
  
  
  if(isset($_POST['q1'])=='A')
  {
  $total =$total + 1;
  include ('process.php');
  
  }
  else{
  
  }
  
  break;
  
  case 2:
  
   echo '&lt;form action="quiz.php" method="post" align="center" id=""&gt;
  &lt;table align="center"&gt;
  &lt;tr&gt;&lt;label name="question" id="ques"&gt;&lt;h1 &gt;HTML stands for?&lt;/h1&gt;&lt;/label&gt;&lt;tr&gt;
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q2" value="A"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Mines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q2" value="B"&gt;&lt;/td&gt;
  &lt;td &gt;Indian Science Of Mines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q2" value="C"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Mineral&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr &gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q2" value="D"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Machines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr &gt;
  
  
  
  &lt;td align="center"&gt;&lt;br&gt;&lt;input type="submit" name="snext" value="Save/Next"&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/form&gt;';
  
  
  if(isset($_POST['q2'])=='C')
  {
  $total =$total + 1;
  include ('process.php');
  
  }
  else{
  
  }
  break;
  
  
  case 3:
  
   echo '&lt;form action="quiz.php" method="post" align="center"&gt;
  &lt;table align="center"&gt;
  &lt;tr&gt;&lt;label name="question" id="ques"&gt;&lt;h1 &gt;CSS stands for?&lt;/h1&gt;&lt;/label&gt;&lt;tr&gt;
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q3" value="A"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Mines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q3" value="B"&gt;&lt;/td&gt;
  &lt;td &gt;Indian Science Of Mines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q3" value="C"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Mineral&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr &gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q3" value="D"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Machines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr &gt;
  
  
  &lt;td align="center"&gt;&lt;br&gt;&lt;input type="submit" name="snext" value="Save/Next"&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;/form&gt;';
  if(isset($_POST['q3'])=='D')
  {
  $total =$total + 1;
  include ('process.php');
  
  }
  else{
  
  }
  break;
  
  
  case 4:
  
   echo '&lt;form action="quiz.php" method="post" align="center"&gt;
  &lt;table align="center"&gt;
  &lt;tr&gt;&lt;label name="question" id="ques"&gt;&lt;h1 &gt;PHP stands for?&lt;/h1&gt;&lt;/label&gt;&lt;tr&gt;
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q4" value="A"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Mines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q4" value="B"&gt;&lt;/td&gt;
  &lt;td &gt;Indian Science Of Mines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q4" value="C"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Mineral&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr &gt;
  &lt;td align="right"&gt;&lt;input type="radio" name="q4" value="D"&gt;&lt;/td&gt;
  &lt;td&gt;Indian School Of Machines&lt;/input&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr &gt;
  
  
  &lt;td align="center"&gt;&lt;br&gt;&lt;input type="submit" name="snext" value="Save/Next"&gt;&lt;br&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;';
  if(isset($_POST['q4'])=='D')
  {
  $total =$total + 1;
  include ('process.php');
  
  }
  else{
  
  }
  break;
  
  
  
  default:
  
  Echo "This is quiz application";
  
  break;
  
  }
  
  }
  
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;?php echo quiz(); ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>