Hi!
So I have an if function and I'm using or in it. It's not working. When I entere texts in the textbox it doesn't say it's correct if it's correct.
It's a quiz sample file.
When I run it it only say correct if I wrote the first answer in the textbox and it doesn't say correct if I write the second answer.
<?PHP
$verbs = array(
'Aller',
);
$verb = array_rand($verbs);
$averb = $verbs[$verb];
$sujets = array(
'Je',
'Tu',
);
$sujet = array_rand($sujets);
$asujet = $sujets[$sujet];
$negposs = array (
'Positive',
);
$negpos = array_rand($negposs);
$anegpos = $negposs[$negpos];
echo "$asujet + $averb => Sentence: $anegpos";
echo '<form action="quiz.php" method="POST">';
echo "<p>Write everything in lowercase</p>";
echo "<input type='text' name='ans' requird>";
echo '<p><input type="submit" value="Refresh Page"</p>';
echo "</form>";
//Check Answer
$ans = $_POST["ans"];
echo "<p>$ans</p>";
if (isset($_POST["ans"])){
if ($averb == "Aller"){
if ($anegpos == "Positive"){
if ($asujet == "Je"){
if ($ans == "je suis allé" || $ans == "je suis allée"){
echo "Correct!";
echo "<p>$averb</p><p>$asujet</p>";
} else {
echo "Wrong";
}
} elseif ($asujet == "Tu"){
if ($ans == "tu es allé" || $ans == "tu es allée"){
echo "Correct!";
} else {
echo "Wrong";
}
} elseif ($asujet == "Il/Elle/On"){
if ($ans == "il a allé" || $ans == "elle a allée" || $ans=="on a allé"){
echo "Correct!";
} else {
echo "Wrong";
}
} elseif ($asujet == "Nous"){
if ($ans == "nous sommes allés" || $ans == "nous sommes allées"){
echo "Correct!";
} else {
echo "Wrong";
}
} elseif ($asujet == "Vous"){
if ($ans == "vous êtes allés" || $ans == "vous êtes allées"){
echo "Correct!";
} else {
echo "Wrong";
}
} elseif ($asujet == "Ils/Elles"){
if ($ans == "ils sont allés" || $ans == "elles sont allées"){
echo "Correct!";
} else {
echo "Wrong";
}
}
}
}
}
?>
Any help appreciated. Thanks Regards
Aucun commentaire:
Enregistrer un commentaire