peter11 Posted August 11, 2010 Share Posted August 11, 2010 i need to say if a variable equals anything but "q2" then echo false however im unsure on how to wright this elseif line. Please help if($points == 2 && $answer == "q2") { echo "Correct"; } elseif($points == 2 && $answer == ??????????){ echo "Try again"; } Link to comment https://forums.phpfreaks.com/topic/210448-if-else-help/ Share on other sites More sharing options...
AbraCadaver Posted August 11, 2010 Share Posted August 11, 2010 elseif($points == 2 && $answer != "q2") { Link to comment https://forums.phpfreaks.com/topic/210448-if-else-help/#findComment-1098128 Share on other sites More sharing options...
peter11 Posted August 11, 2010 Author Share Posted August 11, 2010 I have tried it like this, <?php if($points==0 && $answer=="me"){ setcookie("points", "1", time()+3600); $points ++; echo "CORRECT"; } if($points == 0 && $answer !="me"){ echo "Incorrect - Please try again"; } ?> however when i enter "me" it runs both of these saying CORRECTIncorrect - Please tr again how can it be True and False? Whats wrong with this statement. [/code] Link to comment https://forums.phpfreaks.com/topic/210448-if-else-help/#findComment-1098150 Share on other sites More sharing options...
AbraCadaver Posted August 11, 2010 Share Posted August 11, 2010 however when i enter "me" it runs both of these saying CORRECTIncorrect - Please tr again how can it be True and False? That's impossible with just that code. Link to comment https://forums.phpfreaks.com/topic/210448-if-else-help/#findComment-1098156 Share on other sites More sharing options...
peter11 Posted August 11, 2010 Author Share Posted August 11, 2010 <?php if($points==0 && $answer=="me"){ setcookie("points", "1", time()+3600); $points ++; echo "CORRECT"; } if($points==1 && $answer=="reading"){ setcookie("points", "2", time()+3600); $points ++; echo "CORRECT"; } if($points==2 && $answer=="q2"){ setcookie("points", "3", time()+3600); $points ++; echo "CORRECT"; } if($points==0 && $answer !="me"){ echo "Incorrect - Please try again"; } if($points==1 && $answer !="reading"){ echo "Incorrect - Please try again"; } if($points==2 && $answer !="q2"){ echo "Incorrect - Please try again"; } ?> If you enter it incorrectly it says incorrect however if you enter "me" correctly it says correct and incorrect if you enter "reading" correctly it says correct and incorrect however if you enter "q2" correctly it just says correct. Anyone know why this is? Link to comment https://forums.phpfreaks.com/topic/210448-if-else-help/#findComment-1098174 Share on other sites More sharing options...
peter11 Posted August 11, 2010 Author Share Posted August 11, 2010 Fixed, It was to do with the order, Needed the != statements first as the == statements change the points and make the != statements not match. Link to comment https://forums.phpfreaks.com/topic/210448-if-else-help/#findComment-1098183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.