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 Link to comment https://forums.phpfreaks.com/topic/205647-php-if/ 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. Link to comment https://forums.phpfreaks.com/topic/205647-php-if/#findComment-1076162 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. } Link to comment https://forums.phpfreaks.com/topic/205647-php-if/#findComment-1076178 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. } ?> Link to comment https://forums.phpfreaks.com/topic/205647-php-if/#findComment-1076194 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 Link to comment https://forums.phpfreaks.com/topic/205647-php-if/#findComment-1076215 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 . . . Link to comment https://forums.phpfreaks.com/topic/205647-php-if/#findComment-1076217 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.