Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm creating one quiz application using php and into that I've create one result page which displays the score details about the user and a button to print the certificate. Actually what I need is i need to get the user information in one page like their name, mail id, mbl number, score and print them into another page.

And my code is,

SQL
<?php 
require 'config.php';
if(!empty($_SESSION['name'])){
    
    $right_answer=0;
    $wrong_answer=0;
    $unanswered=0; 
  
   $keys=array_keys($_POST);
   $order=join(",",$keys);
   
   //$query="select * from questions id IN($order) ORDER BY FIELD(id,$order)";
  // echo $query;exit;
   
   $response=mysql_query("select id,answer from questions where id IN($order) ORDER BY FIELD(id,$order)")   or die(mysql_error());
   
   while($result=mysql_fetch_array($response)){
       if($result['answer']==$_POST[$result['id']]){
               $right_answer++;
           }else if($_POST[$result['id']]==5){
               $unanswered++;
           }
           else{
               $wrong_answer++;
           }
   }
   $name=$_SESSION['name'];  
   mysql_query("update users set score='$right_answer' where user_name='$name'");
?>

HTML
<a href="test11.php" class='btn btn-success'>Get Certificate</a>
                  
                       <div style="margin-removed 30%">
                        <p>Total no. of right answers : <span class="answer"><?php echo $right_answer;?></span></p>
                        <p>Total no. of wrong answers : <span class="answer"><?php echo $wrong_answer;?></span></p>
                        <p>Total no. of Unanswered Questions : <span class="answer"><?php echo $unanswered;?></span></p>                   
                       </div> 


In this code I need to get the value of $right_answer and post that into,

HTML
<tr>
		<p><td>Score </td>
		<td name="score"><!--Post the score value Here--></td></p>
</tr>



Anyone help me to do this..


Thanks in advance,
Priya
Posted
Updated 25-Feb-15 20:12pm
v2

You are already using the session variables for the name so why not for the score...
 
Share this answer
 
You may use either a session variable or create a hidden field after this line:
HTML
<p>Total no. of right answers : <span class="answer">
<?php echo $right_answer;  ?></span></p>

add
<?php $_SESSION['score'] = $right_answer; ?>

or
<input type="hidden" name="score" value="<?php echo $right_answer; ?>">
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900