if... else with ||'s and &&'s

My out keeps going to “Everything works!” even when I deliberately leave $stat or $file empty

[php]
$solo = $_POST[‘solo’];
$stat = $_POST[‘stat’];
$file = $_FILES[“file”][“name”];
$category = $_POST[‘category’];

if ($solo == “solo” || $solo == “Solo” || $solo == “SOLO” && !empty($stat) && !empty($file)) {
echo “Everything works!”;
} else {
echo “That’s no moon!”;
}
[/php]

I’m not getting any syntax errors. What could be the problem?

Try this:
[php]if ( preg_match(’/\bsolo\b/i’, $solo) && !empty($stat) && !empty($file) ) {
echo “Everything works!”;
} else {
echo “That’s no moon!”;
}

// a quick note about the preg_match syntax above.
// \b = sets boundaries on the word/pattern IE: means ‘solo’ will match but ‘solos’ will not.
// i = case insensitive
[/php]

Red :wink:

Either wrap your three OR parts in parenthesis or simplify the statement to:
[php]if(strtolower($solo)==‘solo’ && !empty($stat) && !empty($file))[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service