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
LOst in a conditional statement.
Old 02-02-2008, 10:29 AM LOst in a conditional statement.
Defies a Status

Posts: 1,606
Trades: 0
I seem to be lost trying to format a double conditinal statement.

This is the pseudo lines:
if $POST['active'] is not equal to 0 or 1
{do this}
else

This does not work:
PHP Code:
if (($POST['active'] != 0) || ($POST['active'] !=1)) 
Can you tell me what I am doing wrong?

TIA
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-02-2008, 11:02 AM Re: LOst in a conditional statement.
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
Well you could use
PHP Code:
if (!($POST['active']>=&& $POST['active'] <=1))   {... 
edited to add i'm taking as read that you can't use

PHP Code:
 if ($POST['active']>1) {... 

Last edited by maxxximus; 02-02-2008 at 11:07 AM..
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 02-02-2008, 11:25 AM Re: LOst in a conditional statement.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
You just have a logical error. When you say not equal to "0 or 1", what you mean is not equal to 0 and not equal to 1. This code fixes the problem and demonstrates it working as described:

PHP Code:
<?php
if (($_POST['active'] != 0) && ($_POST['active'] != 1))  {
  echo 
"Is NOT 0 or 1";
} else {
  echo 
"Is 0 or 1";
}
?>
<form method="post">
<select name="active">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="submit" value="Check" />
</form>
Also, it's $_POST, not $POST.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE

Last edited by JeremyMiller; 02-02-2008 at 11:30 AM..
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 02-02-2008, 05:50 PM Re: LOst in a conditional statement.
Defies a Status

Posts: 1,606
Trades: 0
Quote:
You just have a logical error. When you say not equal to "0 or 1", what you mean is not equal to 0 and not equal to 1. This code fixes the problem and demonstrates it working as described:
Jermy that may be exactly what I had. My logic flaw sounds right. Unfortunately at this moment I have had a couple of adult beverages too many to try it out.

I did save it and will follow up on this thread.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
Old 02-02-2008, 05:54 PM Re: LOst in a conditional statement.
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
lol. Well, the code I provided should help you out as it's very basic and demonstrates what I believe you wanted. I hope you didn't take my assertion of a flaw in logic as personal. I re-read that and it may have come across as worse than I intended -- I was just speaking of logic from a mathematician's point of view...time for me to get in on some of those adult bevs too.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 02-03-2008, 10:30 AM Re: LOst in a conditional statement.
Defies a Status

Posts: 1,606
Trades: 0
Quote:
I hope you didn't take my assertion of a flaw in logic as personal.

Absolutely not! That is exactly what it was. One would need a pretty thin skin to be upset by that statement.

Rep added and thanks.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to LOst in a conditional statement.
 

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.98649 seconds with 12 queries