SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Dec 2002
    Location
    New Zealand
    Posts
    1,021
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Really Simple if/else Question

    Hi guys,

    I have a really simple problem that has been driving me up the wall. Basically, it has to do with if/else statements. Here is my code:

    PHP Code:
    <?php

    if ($password == "abc") {
        echo 
    "password correct";


    else {
        echo 
    "wrong";
    }

    ?>
    Problem is, no matter what the password variable is set to, it always returns the else statement: http://fitnesstracker.tjrnetworks.co...p?password=abc

    Any ideas what I might be doing wrong? Help would be greatly appreciated.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use php's superglobals
    http://www.php.net/manual/en/languag...perglobals.php

    $_GET['password']

    If you came across some tutorial or book which didn't do this, it's most likely very outdated code that relies on the old register_globals configuration option.

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    meh too slow

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2002
    Location
    New Zealand
    Posts
    1,021
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. I had tried that, but must have made a mistake in the syntax when I tried it earlier. Everything is working fine now. Thanks again for your help.

  5. #5
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one note. always use === instead of == in such case
    or sometimes password can be unexpectedly correct
    PHP Code:
    <?
    $password
    =0;
    if (
    $password == "abc") {
        echo 
    "password correct";
    } else {
        echo 
    "wrong";
    }
    ?>


Bookmarks

Posting Permissions

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