Jump to content

implement a score


tecmeister

Recommended Posts

Hi everyone,

 

Im having problems implementing a score into a quiz.

 

This is the code that im using.

 

<?php
if ($false =="false")
  {
  $score=$score-1;
  };
  
if ($true =="true")
  {
  $score=$score+1;
   };
   echo $score;
?>

 

The problem is when i answer the question it just displays 1 or -1 depending on the question.

I doesn't add or subtract it on to the score.

 

What is the correct code?

 

Thanks for your help.

 

tecmeister

Link to comment
Share on other sites

well if that is all the code you have then obviously score is not set. say you used a form w/ get method and score started at 0 then you use $score=$_GET['score']; and then the rest of your info. Or you could just put all the questions on one page and then make the final score the percent of correct answers over total answers

Link to comment
Share on other sites

Sorry i thought that you was just asking for the php code.

 

This is the first page code:

 


<body>
<table>
<td width="884" align="center">
Welcome to the Quiz

<?php

$username = $_REQUEST['username'];
echo $username;

?> </td>
</table>


<table>
<td>
score
<?php
$score = 0;
echo $score;
?> </td>
</table>
<table>
<p> </p>
<p> </p>
<tr>
  <td>
   Which State in America was the Titanic Heading to?
  </td>
</tr>
<tr>
  <td>
   <form method="post" action="q2.php">
   <table width="133" align="center">
    <tr>
     <td width="112">
   Florida
   </td>
   <td>
     <input type="radio" name="q" value="false" />
   </td>
   </tr>
   <tr>
   <td>
   New York
   </td>
   <td>
   <input type="radio" name="ans" value="true" />
   </td>
   </tr>
   <tr>
   <td>
   Chicago
   </td>
   <td>
   <input type="radio" name="q" value="false" />
   </td>
   </tr>
   <tr>
   <td>
   L.A
   </td>
   <td>
   <input type="radio" name="q" value="false" />
   </td>
   </tr>
   <tr>
   <td align="center"><input type="submit" value="Submit" />
   </td></tr>
   </table>
   </form>
   
   </table>
   

</body>

 

This is the next page:

 


<body>





<table>
<td>
score

<?php
$score = $_GET['score'];
if($true==TRUE) {
$score++;
} else {
$score--;
}
echo $score;
?></td>
</table>
<table>
<p> </p>
<p> </p>
<tr>
  <td width="245">
   How many feet are there in a meter?  </td>
</tr>
<tr>
  <td>
   <form method="post" action="q3.php">
   <table width="133" align="center">
    <tr>
     <td width="112">
   2.4</td>
     <td>
     <input type="radio" name="q" value="false" />
   </td>
   </tr>
   <tr>
   <td>
   4.1</td>

   <td>
   <input type="radio" name="q" value="false" />
   </td>
   </tr>
   <tr>
   <td>
   3.3</td>
   <td>
   <input type="radio" name="ans" value="true" />
   </td>
   </tr>
   <tr>
   <td>
   3</td>
   <td><input type="radio" name="q" value="false" />
   </td>
   </tr>
   <tr>
   <td align="center">
   
   <input type="submit" value="Submit" />
   </td></tr>
   </table>
   </form>
   
</table>
</body>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.