Tæller virker ikke
Ny i php!I linket virker tælleren med opsummering af antal rigtige og antal forkerte svar.
practice your addition facts. (http://www.phpmath.com/demos/arithmetic/practice_1.php)
Hvorfor virker (tæller)scriptet ikke hos mig, når jeg vil bruge det?
Jeg får genereret nye opgaver og får respons om opgaven er løst rigtigt.
<?php
/**
* @author Paul Meagher
* @updated May 18, 2005
*/
session_name("practice");
session_start();
$min_rand = 0;
$max_rand = 18;
$first_number = rand($min_rand, $max_rand);
$second_number = rand($min_rand, $max_rand);
if ($_GET['op'] == "clear") $_SESSION = array();
if (!isset($_SESSION['num_right'])) $_SESSION['num_right'] = 0;
if (!isset($_SESSION['num_wrong'])) $_SESSION['num_wrong'] = 0;
if (!isset($_SESSION['num_probs'])) $_SESSION['num_probs'] = 0;
if ($_POST['form_submitted'] == "yes") {
$fn = $_POST['fn'];
$sn = $_POST['sn'];
$ca = $fn + $sn;
$_SESSION['num_probs']++;
$np = $_SESSION['num_probs'];
$sa = $_POST['submitted_answer'];
if ($ca == $sa) {
echo "<p>Hooray, you answered problem # $np correctly: $fn + $sn = $ca</p>";
$_SESSION['num_right']++;
} else {
echo "<p><font color='red'><b>Darn, you answered problem # $np incorrectly: $fn + $sn = $ca, <i>not</i> $sa</b></font> </p>";
$_SESSION['num_wrong']++;
}
}
?>
<table>
<form method='post' action='<?php echo $_SERVER['PHP_SELF'] ?>'>
<input type='hidden' name='form_submitted' value='yes'>
<input type='hidden' name='fn' value='<?php echo $first_number ?>'>
<input type='hidden' name='sn' value='<?php echo $second_number ?>'>
<tr>
<td><?php echo $first_number ?></td>
<td> + </td>
<td><?php echo $second_number ?></td>
<td> = </td>
<td><input type='text' name='submitted_answer' value='' size='2'></td>
<td><input type='submit' value='Check Answer'></td>
</tr>
</form>
</table>
<br />
Number of right answers: <?php echo $_SESSION['num_right'] ?><br />
Number of wrong answers: <?php echo $_SESSION['num_wrong'] ?><br />
<br />
<a href='<?php echo $_SERVER['PHP_SELF']."?op=clear"; ?>'>Start over</a>.
