Jump to content

Easy IF Statement Help!


Recommended Posts

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";
Link to comment
Share on other sites

Keep in mind that [b]=[/b] is an assignment operator what you want when checking values of a variable or array is a comparison operator which are [b]==[/b] and [b]===[/b] but [b]== [/b]being more commonly used for a normal string variable. This is a common error by those just starting out.
Link to comment
Share on other sites

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'
Link to comment
Share on other sites

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

$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!";
  echo"The \$status variable is not correctly set.";
?> [/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.