lundi 12 janvier 2015

Very simple PHP Quiz for Practice ( IF ELSEIF ELSE Condition ) not working properly

I am trying to teach my self PHP and for practice I decided to create a simple quiz. The radio button options are valued as integers 0 through 2 depending on the question.


The PHP script simply pulls the value from the form adds them and stores data in $sum A message should appear on three possible conditions. The last condition is not rendering properly. Here is the link to show that it is storing the value of $sum



if ($_SERVER["REQUEST_METHOD"] == "POST") {
$one = ($_POST["one"]);
$two = ($_POST["two"]);
$three = ($_POST["three"]);
$four = ($_POST["four"]);
$five = ($_POST["five"]);

$sum = $one + $two + $three + $four + $five;


if ($sum <= 2){
$answer = "Sorry you are not cut out to run your own business!!";
}
elseif ($sum > 2 && $sum <= 4)
$answer = "You are a hustler by nature";
}
elseif ($sum > 4 && $sum <= 7){
$answer = "You are a tycoonist, that will take over the world";
}
else {
$answer = "";
}

Aucun commentaire:

Enregistrer un commentaire