I am tying to get php to display right answer only or display the wrong answer as well as the right one.
I admit that I am not good with php I trying but having no luck so bare with me.
what I am trying or what i to do is to find if someone has answered a question right (in a PHP quiz I trying to do) or wrong.
if they have answered a question right I like to have just there right answer in my HTML page, but if they have answered it wrong I want to display not only one the answer they have selected wrong but also they right answer. this is my code
<!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>
<form method="post" action="">
<h4> Question 1<BR>Which is the port side of a vessel?</h3>
<INPUT TYPE="radio" NAME="answer1" VALUE="Left">Left.<BR><!--Correct-->
<INPUT TYPE="radio" NAME="answer1" VALUE="Right">Right.<BR />
<?php
foreach ($_POST as $Q1){
if ( $_POST == $Q1 ){
break;
echo $Q1;
}
else foreach ($_POST as $Q1) {
$rightAnswer1 ="left";
if ( $_POST !== $Q1){
print "you have answered this wrong<br>";
echo " your answer".$Q1;
echo "<br>Correct answer" .$rightAnswer1;
}
};
}
?>
<h4> Question 2<BR>The bow of a vessel is at the:</h3>
<INPUT TYPE="radio" NAME="answer2" VALUE="Front">Front.<BR><!--Correct-->
<INPUT TYPE="radio" NAME="answer2" VALUE="Back">Back.
<?php
foreach ($_POST as $Q2){
if ( $_POST == $Q2 ){
break;
echo $Q2;
}
else foreach ($_POST as $Q2) {
$rightAnswer1 ="left";
if ( $_POST !== $Q2){
print "you have answered this wrong<br>";
echo " your answer".$Q2;
echo "<br>Correct answer" .$rightAnswer1;
}
};
}
?>
<h4> Question 3<BR>The transom of a vessel is at the:</h3>
<INPUT TYPE="radio" NAME="answer3" VALUE="Front">Front.<BR>
<INPUT TYPE="radio" NAME="answer3" VALUE="Back">Back.<BR><BR><!--Correct-->
<?php
foreach ($_POST as $Q3){
if ( $_POST == $Q3 ){
break;
echo $Q3;
}
else foreach ($_POST as $Q3) {
$rightAnswer1 ="left";
if ( $_POST !== $Q3){
print "you have answered this wrong<br>";
echo " your answer".$Q3;
echo "<br>Correct answer" .$rightAnswer1;
}
};
}
?>
<INPUT TYPE="submit" VALUE="Score Quiz!" >
<BR><BR>
</form>
<body>
</body>
</html>