You are here: Re: [PHP] Using the OR operator in an IF statement « PHP « IT news, forums, messages
Re: [PHP] Using the OR operator in an IF statement

Posted by Jason Wong on 01/08/05 15:02

On Saturday 08 January 2005 19:02, Tim Burgan wrote:

> Can someone please correct me on my efforts below.
> If I have a condition where I want to test if a variable is not equal to
> "student", "staff", or "admin".. what's the simplest was to achieve that?
>
> Here's what I tried.. that didn't work:
>
> <?php
> if ( ($_POST['usertype'] != "student") || ($_POST['usertype'] !=
> "staff") || ($_POST['usertype'] != "admin") )
> {
> // ...
> }
> ?>

You need to use 'AND' (or '&&').

Or you can use in_array():

$usertype = array('student', 'staff', 'admin');
if (in_array($_POST['usertype'], $usertype)) {
// valid usertype;
} else {
// invalid usertype
}

--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
------------------------------------------
New Year Resolution: Ignore top posted posts

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация