samedi 30 mai 2020

how to calculate quizs

I want to make a test system. For this, there are "id", "question", "correct", "A", "B", "C", "D", "E" columns in the database. And in the "correct" column, I enter one of the values "A", "B", "C", "D" or "E". However, after entering the user response, I cannot automatically find the correct and wrong number on the result.php page. And I can't calculate the user score.

this is form :

<form action="result.php" method="post">
    <?php 
    /*n */
    include 'ayar.php';
    $v=$db->prepare("select * from riyaziyyat where id IN(1,2,3)");
    $v->execute(array());
    $x=$v->fetchALL(PDO::FETCH_ASSOC);
    foreach ($x as $key => $b) {  
    ?> 
    <div class="cavablardivi">
    <input type="radio" name="<?php echo $b["id"];?>" value="A"><span class="radioherf">A</span><br>
    <input type="radio" name="<?php echo $b["id"];?>" value="B"><span class="radioherf">B</span><br>
    <input type="radio" name="<?php echo $b["id"];?>" value="C"><span class="radioherf">C</span><br>
    <input type="radio" name="<?php echo $b["id"];?>" value="D"><span class="radioherf">D</span><br>
    <input type="radio" name="<?php echo $b["id"];?>" value="E"><span class="radioherf">E</span><br>
    </div>
    <?php } ?>
    <input type="submit" name="send" value="finnish">
</form>

and this is resul.php :

<?php 

$corrects=0;
$wrongs=0;
include 'ayar.php';
$v=$db->prepare("select * from riyaziyyat where id IN(1,2,3) limit 100");
$v->execute(array());
$x=$v->fetchALL(PDO::FETCH_ASSOC);
foreach ($x as $key => $b) {
if ($_POST['$b["id"]'] and $_POST['$b["id"]']==$b["correct"]) {
        $corrects++;} 
 else { $wrongs++;}
} 

echo "your corrects ---> ".$corrects; 
echo "<br>"; 
echo "your wrongs ---> ".$wrongs;
         
?>

enter image description here

Aucun commentaire:

Enregistrer un commentaire