I have very limited knowledge in php and will appreciate any help.
I am trying to create a php quiz, where every question is on different page. On the third page the answers from 1st and 2nd page are scored and calculated. The problem is that I only get score for last answer (from 2nd page)
I tried to use Sessions but probably messed up something. Also I don't use data base for this.
On first page (q1.php) I have this form
<form action="q2.php" method="post"><li>
<h3>Koji ste pol?</h3>
<div>
<input type='radio' name='answer1' id='answer1' value='A' />
<label for='answer1A'>Muško</label>
</div>
<div>
<input type='radio' name='answer1' id='answer1' value='B' />
<label for='answer1B'>Žensko</label>
</div>
</li><input type="submit" value="posalji" /></form>
On second page (q2.php) I have this code
<?php
session_start();
$_SESSION['answer1'] = $_POST['answer1'];
?>
<form action="rezultat.php" method="post"><li>
<h3>Da li ste zaposleni?</h3>
<div>
<input type='radio' name='answer2' id='answer2' value='A' />
<label for='answer2A'>Da</label>
</div>
<div>
<input type='radio' name='answer2' id='answer2' value='B' />
<label for='answer2B'>Ne</label>
</div>
</li><input type="submit" value="posalji" /></form>
And on third page (rezultat.php) the answers from 1st and 2nd page need to be calculated
<?php
session_start();
$_SESSION['answer1'] = $_POST['answer1'];
$_SESSION['answer2'] = $_POST['answer2'];
?>
Vaš rezultat je:
<?php
$answer1= $_POST['answer1'];
$answer2= $_POST['answer2'];
$score = 0;
if ($answer1 == "A"){$score += 5;}
if ($answer1 == "B"){$score += 4;}
if ($answer2 == "A"){$score += 1;}
if ($answer2 == "B"){$score += 5;}
echo "$score"; ?>
Please help, thank you in advance.