Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    IF Statement Evaluates TRUE always

    Hi guys, what is causing this statement to eval to true all the time?

    PHP Code:
    <?php if ($_SERVER['PHP_SELF'] = "help.php") { echo "help_on.jpg"; } else { echo "help_off.jpg"; } ?>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,025
    Thanks
    2
    Thanked 314 Times in 306 Posts
    = is an assignment operator
    == is an equal comparison operator

    $_SERVER['PHP_SELF'] = "help.php" sets $_SERVER['PHP_SELF'] equal to "help.php" and since the result of that is not false, the if() statement evaluates to TRUE.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    <?php if ($_SERVER['PHP_SELF'] == "help.php") { echo "help_on.jpg"; } else { echo "help_off.jpg"; } ?>


    woops allready done
    Last edited by runnerjp; 05-17-2008 at 07:27 PM. Reason: sorry whent to grab patato out of oven and didnt hit send lol


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •