Solved

what is wrong with this statment in php?

Posted on 2008-06-12
4
175 Views
Last Modified: 2010-04-21
$type="gif";
if(($type!="gif") || ($type!="jpeg") || ($type=="gif"))
{
echo "You can only upload a photo";
}

and when i run it i get
You can only upload a photo
why?
0
Comment
Question by:mgtm3
4 Comments
 
LVL 27

Accepted Solution

by:
yodercm earned 500 total points
ID: 21769606
You are using the OR operator, so if any one of the conditions is true, the echo will operate.  Obviously, in this case, it will always be true because of the first and last conditions.
0
 
LVL 48

Expert Comment

by:hernst42
ID: 21769612
$type!="gif" or ($type=="gif")
is allways true, remove ($type=="gif") or replace it with
($type!="png")
0
 

Author Closing Comment

by:mgtm3
ID: 31466555
thanks
0
 
LVL 82

Expert Comment

by:hielo
ID: 21769635
You need an AND condition and don't need the $type=="gif"


$type="gif";
if(($type!="gif")&& ($type!="jpeg") )
{
echo "You can only upload a photo";
}
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question