I'm working on this project and I keep running into some issues. First off, it's a quiz that needs to calculate the percentage correct and out put it (all the code will be at the end). The issue with it right now is that it's always calculating 0%, even with right answers and a variable is defined for it. My second issue is that it's not sticky and it needs to be. I don't know what's going on with that. I have only one line done right now and it's not sticky. Help?
<!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>Untitled Document</title>
</head>
<body>
<form method="post">
<?php
$score = 0;
$percent = 0;
//checking submit button
if(isset($_POST['submit'])){
}
//multi-dimensional arrays for questions, selections, and answers
$questions = array(
'q1' => array('question' => 'Which is optional to making Easy Fudge?',
'choice 1' => 'Nuts',
'choice 2' => 'Condensed Milk',
'choice 3' => 'semi-sweet morsels',
'choice 4' => 'bakers chocolate <br />',
'answer' => 'nuts
'),
'q2' => array('question' => 'One square of bakers chocolate is optional to help enhance the flavor and texture?',
'choice 1' => 'Yes',
'choice 2' => 'No',
'choice 3' => 'I do not know what this bakers chocolate is.',
'choice 4' => 'Maybe. <br />',
'answer' => 'Yes', ),
'q3' => array('question' => 'Between prepration time, cooking time, and cooling time, how long does it take to make Easy Fudge?',
'choice 1' => '130 minutes',
'choice 2' => '131 minutes',
'choice 3' => '132 minutes',
'choice 4' => '133 minutes <br />',
'answer' => '131 minutes',),
'q4' => array('question' => 'If divided into 48 pieces, 2 pieces of this fudge is how many calories?',
'choice 1' => '140 calories',
'choice 2' => '150 calories',
'choice 3' => '160 calories',
'choice 4' => '170 calories <br />',
'answer' => '160 calories'),
'q5' => array('question' => 'You combine your morsels and sweetend condensed milk in a medium sauce pan over which heat?',
'choice 1' => 'low',
'choice 2' => 'medium-low',
'choice 3' => 'medium',
'choice 4' => 'high <br />',
'answer' => 'low'),
);
//radio buttons and selectability
foreach($questions as $key => $question){
echo $question['question'] . '<br />';
// TODO: check the POST value and compare to this value (ie. "one")
echo '<input type="radio" name = "'.$key.'" value="one"> ' . $question['choice 1'] . '<br />';
//echo (isset($_POST['radio'] and $_POST['radio']== "one") )? "checked" : "";
echo '<input type="radio" name = "'.$key.'" value="two" >' . $question['choice 2'] . '<br />';
echo '<input type="radio" name = "'.$key.'" value="three"> ' . $question['choice 3'] . '<br />';
echo '<input type="radio" name = "'.$key.'" value="four"> ' . $question['choice 4'] . '<br />';
}
//looping through the questions with nested loops
if (isset($_POST["submit"])) {
foreach($questions as $key => $question){
if ( $question['answer']== $_POST[$key]){
$score++;
}else{ $score = $score;
}
}echo $score;
}//= ($score/5)*100 . "%";
?>
<input name="submit" type="submit" />
</form>
</body>
</html>