Hi guys I'm new (ish) to PHP and have a problem with the below code: <?php $total = $_GET['total']; if ($total <=5){ echo "<b>You Fail</b> <br><br>"; } elseif ($total == 6 or 7){ echo "<b>Not great, but not bad</b> <br><br>"; } else{ echo "<b>Nice work</b> <br><br>"; } echo "Test Complete, you correctly answered $total<br><a href='index.php?start=1'>Test Again</a>"; ?> When the script runs and $total is 5 or below "You Fail" is echo'ed. If $total is 6 or 7 "Not great, but not bad" is echo'ed as expected. BUT if $total is 8 or higher "Not great, but not bad" is still echo'ed but I wanted "Nice work" printed, because $total is not lower 5 or lower nor is it 6 or 7, so I though the script would echo whats in the "else" section. Can someone help please!! cigi
you can try this <?php $total = $_GET['total']; if ($total <=5){ echo "<b>You Fail</b> <br><br>"; } elseif ($total <= 7){ echo "<b>Not great, but not bad</b> <br><br>"; } else{ echo "<b>Nice work</b> <br><br>"; } echo "Test Complete, you correctly answered $total<br><a href='index.php?start=1'>Test Again</a>"; ?>
no worries if you're wondering why your code was not working before, on this line elseif ($total == 6 or 7){ you should have written it this way $total == 6 OR $total == 7) hope that helps
Thanks again serialCoder I was going to ask why it did not work, I see how it works now, stating the variable for each value. But I think I will leave as <=7 though, seems to be the best way to code it as you advised. Many thanks!! cigi