stevens Posted July 10, 2006 Share Posted July 10, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/ Share on other sites More sharing options...
micah1701 Posted July 10, 2006 Share Posted July 10, 2006 $status = "test"should be$status == "test" Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55335 Share on other sites More sharing options...
Houdini Posted July 10, 2006 Share Posted July 10, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55342 Share on other sites More sharing options...
stevens Posted July 10, 2006 Author Share Posted July 10, 2006 The status = "test" works fine, but i will change it to == anyway. The problem seems to be with the brackets and || maybe? Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55345 Share on other sites More sharing options...
micah1701 Posted July 10, 2006 Share Posted July 10, 2006 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' Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55348 Share on other sites More sharing options...
Houdini Posted July 10, 2006 Share Posted July 10, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55351 Share on other sites More sharing options...
stevens Posted July 10, 2006 Author Share Posted July 10, 2006 Houdini thankyou for your reply, i understand that now. Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55366 Share on other sites More sharing options...
stevens Posted July 10, 2006 Author Share Posted July 10, 2006 How can i make this return cost_check if they dont match?This doesnt work:[code]if (!$cost_check == $status) { echo "$cost_check";}else {echo "ok"; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55367 Share on other sites More sharing options...
cmgmyr Posted July 10, 2006 Share Posted July 10, 2006 [code]if ($cost_check != $status) { echo "error";}else { echo "$cost_check";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55368 Share on other sites More sharing options...
stevens Posted July 10, 2006 Author Share Posted July 10, 2006 D'oh!Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55378 Share on other sites More sharing options...
cmgmyr Posted July 10, 2006 Share Posted July 10, 2006 It's almost too simple ;D Quote Link to comment https://forums.phpfreaks.com/topic/14131-easy-if-statement-help/#findComment-55379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.