!= || != || != always returns true?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

!= || != || != always returns true?

Post by JAB Creations »

For some reason this code is always returning true (and echoing) even when I make a request like index.php?audio=2 on the page. What am I doing wrong here?

Code: Select all

<?php
if ($_GET['audio'] != "0" || $_GET['audio'] != "1" || $_GET['audio'] != "2")
 {echo 'if you requested "index.php?audio=2" then this message should not appear';}?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Replace the || with &&, essentially you are saying if any one of those pass let them in. Therefore, when ?audio=2 is checked against if ($_GET['audio']==1) then it evaluates true.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Post by JAB Creations »

Ops! It worked, thanks! :lol:
Post Reply