Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-23-2007, 11:35 AM IF OR inclusion
Novice Talker

Posts: 11
Name: Keith
Trades: 0
I want to allow if account_type = 1 or 2

This is my code now but it doesent work.

PHP Code:
<?php
if($_SESSION["account_type"] !== "1" || !== "2") {
 
}
?>
kknoer is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-23-2007, 12:06 PM Re: IF OR inclusion
Ultra Talker

Posts: 483
Trades: 0
You want:

if( ($_SESSION["account_type"] == 1) || ($_SESSION["account_type"] == 2) ) {

A few points:
1) You need to do each comparison completely (as opposed to the "if value equals 1 or 2" you need to do "if value equals 1 or value equals 2").
2) When comparing with numbers, don't put the numbers in quotes. You are comparing to a string that represents a number... normally this works, but not always.
3) !== is "NOT equals" not "equals" which is what you really wanted.
4) Using the '!==' and '===' operators compares types, too, which is really not what you want here... hence you would use '!=' or '==' instead.
__________________

Please login or register to view this content. Registration is FREE
TwistMyArm is offline
Reply With Quote
View Public Profile
 
Old 08-23-2007, 12:10 PM Re: IF OR inclusion
coolkbk585's Avatar
Be good this Christmas!

Latest Blog Post:
KBlog has been deativated
Posts: 642
Name: Kyle
Location: Ada, MI
Trades: 0
Try && instead of ||
__________________
<?php if($Adsense_Revenue > 0): define('HAPPINES','100%'); else: define('HAPPINESS', '0%') endif; ?>
coolkbk585 is offline
Reply With Quote
View Public Profile Visit coolkbk585's homepage!
 
Old 08-23-2007, 12:27 PM Re: IF OR inclusion
Skilled Talker

Posts: 94
Trades: 0
PHP Code:
 <?php
if($_SESSION["account_type"] == "1" || == "2") {
    echo 
"Not a valid account type.";
}
?>

Removed the ! which mean is not identical
__________________
Sell Templates? Try our
Please login or register to view this content. Registration is FREE
! See a live
Please login or register to view this content. Registration is FREE
ChadR is offline
Reply With Quote
View Public Profile
 
Old 08-23-2007, 02:56 PM Re: IF OR inclusion
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Here is about five different ways I could think of to test this argument...

PHP Code:
if ($_SESSION['account_type'] == OR $_SESSION['account_type'] == 2) . . .
 
if (
$_SESSION['account_type'] > OR $_SESSION['account_type'] < 3) . . .
 
if (
in_array($_SESSION['account_type'], array(12))) . . .
 
if (
abs((int)$_SESSION['account_type']) AND (int)$_SESSION['account_type'] <= 2) . . .
 
if (
floor($_SESSION['account_type']) AND abs(inval($_SESSION['account_type'])) < 3) . . . 
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 08-23-2007, 04:02 PM Re: IF OR inclusion
Super Talker

Posts: 130
Trades: 0
Quote:
Originally Posted by coolkbk585 View Post
Try && instead of ||
Using && instead of || would mean that both sides would have to be true. Meaning $_SESSION['account_type'] would have to equal 1 and also equal 2. This could never happen because if a variable equals 1 than it cannot equal 2 and vice versa.
__________________
flann

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
flann is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to IF OR inclusion
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27729 seconds with 12 queries