Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

what is wrong with this statment in php?

Posted on 2008-06-12
4
Medium Priority
?
182 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:
Cornelia Yoder earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

927 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