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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.