Jump to content

problem with if else if statement


kahuna

Recommended Posts

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  :shrug: ,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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.