Jump to content

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.

[code]
$status = $_POST['status'];

if ((!strstr($response, "AUTHORISED"))||($status = "test")) {
    echo "denied";
}
else {
    echo "accepted";
}
[/code]
Link to comment
https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/
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
https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55342
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
https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55348
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

[code=php:0]<?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.";
}
?> [/code]
Link to comment
https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55351
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.

Guest
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.