Hey guys, the code keeps incrementing if i refresh for example.
The quiz consists of 3 parts, built up of 3 different aray for each of the questions and answers to the quiz. If i refresh a page then the score will increment still, I dont know what i done wrong or how to get around this..... i tried everything.
Thanks for the help in advance.
Lance
<?php
session_name("Question_Test");
session_start();
$_SESSION['score'];
$_SESSION['score1'];
require_once('questionsandanswers3.php');
require_once('functions.php');
$score = 0;
if (!isset($_POST['submit']))
{
$_SESSION['correct'] = array();
$_SESSION['wrong'] = array();
$_SESSION['finished'] = 'no';
if (isset($_SESSION['error']))
{
unset($_SESSION['error']);
$num = 0;
}
else
{
$_SESSION['score2'] = $score;
$_SESSION['correct'] = array();
$_SESSION['wrong'] = array();
$_SESSION['finished'] = 'no';
$num = 0;
}
}
else
{
$num = (int) $_POST['num'];
$postedanswers = str_replace("_"," ",$_POST['answers']);
if ($postedanswers == $answers[$num]['0'])
{
$_SESSION['score2'] ++;
$_SESSION['correct'][] = $postedanswers;
}
else
{
$_SESSION['wrong'][] = $postedanswers;
}
if ($num < count($questions)-1)
{
$num++;
}
else
{
$last = true;
$_SESSION['finished'] = 'yes';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>running an array</title>
<?php
echo $_SESSION['score2'];
if (!isset($last)) {
echo "<script type=\"text/javascript\" src=\"form.js\"></script>";
}
?>
</head>
<body>
<?php if (!isset($last)){?>
<h1>Resolving Section</h1>
<h2>Questions <?php echo $num+1; ?>:</h2>
<p><strong><?php echo $questions[$num]; ?></strong></p>
<form id="questionBox" method="post" action="resolve.php">
<table width="644" border="1">
<tr>
<td width="321">
<?php
$pattern = ' ';
$replace = '_';
$shuffledAnswers = shuffle_assoc($answers[$num]);
#var_dump($newanswers);
foreach ($shuffledAnswers as $answer)
{
$answer2 = str_replace($pattern,$replace,$answer);
echo "<li><input type=\"radio\" id=\"$answer2\" value=\"$answer2\" name=\"answers\" />\n";
echo "<label for=\"$answer2\">$answer</label></li>\n";
}
?>
</td>
</tr>
</table>
<input type="hidden" name="num" value="<?php echo $num; ?>" />
<input type="submit" id="submit" name="submit" value="Submit Answer" /></p>
</form>
<?php
} else
{
echo "<p id=\"compare\"><a href=\"results.php\">results Section! <img src=\"images/arrow.png\" /></a></p>";
}
?>
</body>
</html>