Hey guys, I have a quick question. I normally only do Front-End but I have just started working more with PHP. So I have a question regarding conditionals. Here is my code:

//I actually get this from when a user posts, this is for demo
$videoURL = "http://www.youtube.com/watch?v=-XjwL9kCmgc";

$parsedURL = parse_url($videoURL);
$videoProvider = $values[1]; //prints first value aka host (www.youtube.com)

if($videoProvider != 'www.youtube.com' || $videoProvider != 'vimeo.com') {
    $errors[] = "<p>$videoProvider is not allowed. Must be from Youtube or Vimeo!</p>";
else if () {

else {
 //do this... submit form

So what's happening is the initial if statment with the || conditional is not excuting it is allowing all videos to submitted still ... I have other conditonals below it that work fine like

   `else if (strlen($videoURL)<0){
        $errors[] = "<p>Video URL empty!</p>";

Any help would be greatly appreciated! Thanks :)

4 Years
Discussion Span
Last Post by drewpark88

I suggest you use extra parenthesis to force correct execution:

if (($videoProvider != 'www.youtube.com') || ($videoProvider != 'vimeo.com'))

The extra parenthesis work when I remove || ($videoProvider != 'vimeo.com') but for some reason that OR statment breaks it ... not sure why? I removed it and submitted youtube url and it worked fine like this .. not sure what I'm doing wrong. Thanks for the help btw, any suggestions?

if (($videoProvider != 'www.youtube.com')){

Probably your logic. I think what you want to happen is (I didn't check the first time):

if (($videoProvider != 'www.youtube.com') && ($videoProvider != 'vimeo.com'))

I replaced or with and, because you want to add the error when your video provider is other than those two. Another way to write the above is:

if (! (($videoProvider == 'www.youtube.com') || ($videoProvider == 'vimeo.com')))

Edited by pritaeas

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.