kahuna Posted October 18, 2010 Share Posted October 18, 2010 Hi im new to this site so i hope this is in the right place,my table goes green when i try to say less than 14 but when i use greater the code looks ok ,its works by itself but im using five similar else if statements for different ages(teacher doesnt want functions used yet) can anyone please help ??? else if($myAge >9 || $myage <14) { echo"<table width='500' border='0' cellpadding='0' cellspacing='1' bgcolor='#CCCCCC'>"; echo"<tr>"; echo"<td>"; echo"<table width='100%' border='0' cellpadding='3' cellspacing='1' bgcolor='#FFFFFF'>"; echo"<tr>"; echo"<td colspan='3'><h3><strong>Sports Catagory</h3></strong></td>"; echo"</tr>"; echo"<tr>"; echo"<td><hr></td>"; echo"</tr>"; echo"<tr>"; echo"<td> ".$username." a-zA-z</td>"; echo"</tr>"; echo"<tr>"; echo"<td> ".$password." 0-9</td>"; echo"</tr>"; echo"<tr>"; echo"<td>Invalid data entered, please re-enter the data correctly</td>"; echo"</tr>"; echo"<tr>"; echo"</tr>"; echo "<tr>"; echo "<td><a href = '".$self."'> Back to Form </a></td>"; echo "</tr>"; echo "</table>"; echo"</td>"; echo"</tr>"; echo"</table>"; } Link to comment https://forums.phpfreaks.com/topic/216199-problem-with-if-else-if-statement/ Share on other sites More sharing options...
Pikachu2000 Posted October 18, 2010 Share Posted October 18, 2010 Read the condition to yourself: "If myAge is greater than 9, or less than 14", and you'll see that any number will return TRUE, because every number is either less than 14 or greater than 9. You likely meant to use "If myAge is greater than 9 AND less than 14", which would be: elseif( $myAge > 9 && $myAge < 14 ), which will result in TRUE for 10, 11, 12, and 13. Link to comment https://forums.phpfreaks.com/topic/216199-problem-with-if-else-if-statement/#findComment-1123634 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.