Jump to content


Photo

Easy IF Statement Help!


  • Please log in to reply
10 replies to this topic

#1 stevens

stevens
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 10 July 2006 - 12:49 AM

Hi there is something wrong with my if statement, please let me know what it is!! It doesnt echo denied! Im trying to only get accepted; if status doesnt = "test" and it is authorised.

$status = $_POST['status'];

if ((!strstr($response, "AUTHORISED"))||($status = "test")) {
    echo "denied"; 
}
else {
    echo "accepted";
}

I wish i'd have thought up www.500wordsite.com !

#2 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 10 July 2006 - 12:56 AM

$status = "test"

should be

$status == "test"
"Confidence in the face of risk."

#3 Houdini

Houdini
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 10 July 2006 - 01:03 AM

Keep in mind that = is an assignment operator what you want when checking values of a variable or array is a comparison operator which are == and === but == being more commonly used for a normal string variable. This is a common error by those just starting out.
We the unwilling, led by the unknowing,
have done so much, for so long, with so little,
that we are now quqlified to do anything, with nothing!

#4 stevens

stevens
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 10 July 2006 - 01:07 AM

The status = "test" works fine, but i will change it to == anyway. The problem seems to be with the brackets and || maybe?
I wish i'd have thought up www.500wordsite.com !

#5 micah1701

micah1701
  • Members
  • PipPipPip
  • Advanced Member
  • 613 posts
  • LocationEllington, CT USA

Posted 10 July 2006 - 01:14 AM

where is the variable $response getting its value from?

your if/then statment is checking the string value in $response to see if it contains the word "AUTHORISED".

Where in your code is $response populated?
Also, the word is spelled "AUTHORIZED" with a 'z'
"Confidence in the face of risk."

#6 Houdini

Houdini
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 10 July 2006 - 01:18 AM

Not really because what is happening is that you are assigning the value of 'test' to the variable $status regardless of what it was prior to that statement. If the $_POST['status'] was "" or nothing when it gets to $status='test' then PHP will assign the value on the right to the variable on the left whereas $status =='text' will check the value of $status and if it is 'test' then it will return true otherwise it would return false if it were"" or nothing and fail. Here is an example to illustrate what I just stated

<?php 
$status = "UH OH";
if($status==""){//remove the second = sign and retest to see the result it will execute the else statement
  echo "$status contains no printable characters"; 
}
	elseif($status=="UH OH"){
	  echo"The proper value of $status is in the \$status variable!";
	}
	else{
	  echo"The \$status variable is not correctly set.";
	}
 ?>

We the unwilling, led by the unknowing,
have done so much, for so long, with so little,
that we are now quqlified to do anything, with nothing!

#7 stevens

stevens
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 10 July 2006 - 02:05 AM

Houdini thankyou for your reply, i understand that now.
I wish i'd have thought up www.500wordsite.com !

#8 stevens

stevens
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 10 July 2006 - 02:13 AM

How can i make this return cost_check if they dont match?

This doesnt work:
if (!$cost_check == $status) {
    echo "$cost_check";
}
else {
echo "ok";
     }
}

I wish i'd have thought up www.500wordsite.com !

#9 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 10 July 2006 - 02:16 AM

if ($cost_check != $status) {
    echo "error";
}else {
    echo "$cost_check";
}


#10 stevens

stevens
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 10 July 2006 - 02:42 AM

D'oh!

Thanks.
I wish i'd have thought up www.500wordsite.com !

#11 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 10 July 2006 - 02:43 AM

It's almost too simple  ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users