zero_ZX Posted June 23, 2010 Share Posted June 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted June 23, 2010 Share Posted June 23, 2010 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. Quote Link to comment Share on other sites More sharing options...
B0b Posted June 23, 2010 Share Posted June 23, 2010 if ( $row['personale'] != '1' && $row['personale'] != '2' ) { // Is not 1 and is not 2: not admin. } else { // Is admin. } Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted June 23, 2010 Share Posted June 23, 2010 why not check that it IS admin... <?php if ( $row['personale'] > 2 ) { // do admin stuff. } else { // do other stuff. } ?> Quote Link to comment Share on other sites More sharing options...
zero_ZX Posted June 23, 2010 Author Share Posted June 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 23, 2010 Share Posted June 23, 2010 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 . . . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.