I would like to display count of correct answers, but my page is reloading after submit.Code is comparing data after load, not input data. How I should prevent to not refresh/reload page after submit and just display results. I do not want you use Javascript or Jquery
if use How to avoid page reload in php form submission after submit my page, just redirect to new tab, nothing else happen and I will receive new questions and choice to play the game. Looks like there is problem with foreach loop, that it is looping every time submit is processed.
How I can disable refreshing page after submit?
<?php
include "sql.php";
?>
<body>
<form method="POST" >
<ul>
<?php foreach($list as $key=>$value) :?>
<?php
$option = [$value['capitol'], $value['choice1'], $value['choice2']];
shuffle($option);
?>
<li> <h5>What is capitol city of <?php echo $value['country']."?";?></h5> </li>
<input type="radio" name="<?=$value['id']?>" value="<?=$option[0]?>" required> <?=$option[0]?>
<br>
<input type="radio" name="<?=$value['id']?>" value="<?=$option[1]?>" > <?=$option[1]?>
<br>
<input type="radio" name="<?=$value['id']?>" value="<?=$option[2]?>" > <?=$option[2]?>
<br>
<?php endforeach;?>
</ul>
<input type="submit" name='submit'>
</form>
</body>
<?php
if(isset($_POST['submit'])){
$correct=0;
foreach($list as $key=>$value){
$answer = $_POST[$value['id']];
if($answer == $value['capitol'] ){
$correct++;
}
}
echo "Correct answers " .$correct;
}
?>
</html>