eddy556 Posted May 25, 2008 Share Posted May 25, 2008 Hi, I need help on how to use multiple conditions within an IF statement. Through research I have found that you and test if both conditions are true using && but I need to test for OR. I was thinking it should look something like: if($filetype != ".mp3" || $filetype != ".MP3") and this doesn't throw an error. I'm sure its simple. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/107198-mulitple-conditions-in-if-statement/ Share on other sites More sharing options...
.josh Posted May 25, 2008 Share Posted May 25, 2008 if(($filetype != ".mp3") || ($filetype != ".MP3")) if that doesn't work then I would suggest echoing $filetype to see if it's holding what you expect it to be holding. Quote Link to comment https://forums.phpfreaks.com/topic/107198-mulitple-conditions-in-if-statement/#findComment-549603 Share on other sites More sharing options...
PFMaBiSmAd Posted May 25, 2008 Share Posted May 25, 2008 Rather than test for all possible "cases" (.mp3, .Mp3, .mP3, .MP3 could all be entered), I recommend converting to lowercase using strtolower() and doing one test that would match all possible letter cases. Quote Link to comment https://forums.phpfreaks.com/topic/107198-mulitple-conditions-in-if-statement/#findComment-549615 Share on other sites More sharing options...
deadonarrival Posted May 25, 2008 Share Posted May 25, 2008 if (filetype isn't mp3 or filetype isn't MP3) Apart from anything else, that would ALWAYS run the block. You may aswell just run the if block. I'm finding it hard to put this into words, it's an odd idea, but you're basically saying if ((number is not one) OR (number is not 2)) do this If we input 1 if ((number is not one FALSE) or (number is not two TRUE)) do this input 2 if ((number is not one TRUE) or (number is not two FALSE)) do this input anything apart from one or two if ((number is not one TRUE) or (number is not two TRUE)) do this whatever you do, you're saying if TRUE or FALSE = TRUE do this if FALSE or TRUE = TRUE do this if TRUE or TRUE = TRUE do this Your if statement cannot return false, so the block will always return true. I think you actually want $filetype = strtolower($filetype); if($filetype == ".mp3") { #Do this if it IS an mp3 } else { #Do this if it IS NOT an mp3 } I hope this clarifies Quote Link to comment https://forums.phpfreaks.com/topic/107198-mulitple-conditions-in-if-statement/#findComment-549630 Share on other sites More sharing options...
eddy556 Posted May 25, 2008 Author Share Posted May 25, 2008 In response to that last post the IF statement CAN return false. Say a user attempts to upload a .txt file.....? I'm going to use the strtolower route Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/107198-mulitple-conditions-in-if-statement/#findComment-549645 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.