Jump to content

PHP if


zero_ZX

Recommended Posts

Hey,

To start off with,

This board really rocks, I've learned so much, and I can even code my own scripts from scratch now ^^

Anyway, i ran into a problem which I don't think i can solve by myself.

 

I have the following code:

$staff = $_SESSION['valid_user'];

$result = mysql_query("SELECT * FROM kunder WHERE brugernavn=('$staff')  LIMIT 1");
$row = mysql_fetch_array($result);

if ($row["personale"] != "1" || $row["personale"] != "2")
{
echo '

<div class="response-msg error ui-corner-all">
						<span>Meddelelse</span>
						Adgang til denne side blev nægtet af serveren.
                            <br />
                            Du har muligvis ikke fået tildelt en personale konto. Kontakt din administrator vedrørende dette problem.
					</div>



												<div class="clear"></div>

				<div class="clear"></div>

			<div class="clear"></div>

			<div class="clear"></div>';

			include('sidebar.php');
echo'		</div>
		<div class="clear"></div>
	</div>
</div>';
include('footer.php'); 
echo '</div>
</body>
</html> ';

exit();						


}

 

So i have this if condition:

if ($row["personale"] != "1" || $row["personale"] != "2")

 

Which should make sure that if your not an admin then die.. However it kicks every one outs, as it doesn't work, even when my personale value for my current account is 1 or 2, i always get the message denied msg..

 

Can any one help? Eventually with debugging.. that's one thing i didn't learn yet :(

Link to comment
Share on other sites

if( $a != $b || $a != $c){ 
     // stuff 
}

 

Will always evaluate to true...

 

$a cannot be $b AND $c, so one of the situations will always be false, which with your or, will evaluate to true.

 

Thanks m8 :)

 

And of cause thanks to the others of you trying to help :)

Link to comment
Share on other sites

if( $a != $b || $a != $c){ 
     // stuff 
}

 

Will always evaluate to true...

 

$a cannot be $b AND $c, so one of the situations will always be false, which with your or, will evaluate to true.

 

Unless, of course, $b == $c . . .

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.