Page 1 of 1

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

Posted: Wed May 02, 2007 10:39 pm
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';}?>

Posted: Wed May 02, 2007 11:02 pm
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.

Posted: Thu May 03, 2007 10:42 pm
by JAB Creations
Ops! It worked, thanks! :lol: