PHP bug fixing - condition not working properly

141 views Asked by At

In the PHP code when put $result variable more than 100. Then output should be "Your result is invalid". But it's showing "You have passed". Why? Can anybody help me please?

Check code here - https://pasteboard.co/HZkC73C.png

2

There are 2 answers

0
illia permiakov On

Cause your variable has value greater than 33 and greater than 100 in the same time, and it goes only into first IF statement block. If you need second statement to be valid - switch IF and ELSE IF blocks.

1
Pawan Kumar On
<?php  
$result=130;  
if($result >=30 && $result <=100){
echo "You have  passed";
}
elseif ($result < 0 || $result >100) {
echo "Your result is invalid";
}
else {
echo "fail";
}
?>