SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: if else

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if else

    what is wrong with the following statement :

    if (isset ($_GET['err']) && $_GET['err'] == 'true') {
    $errmsg = "An error occured while validating username and password. Some fields are left empty. Please try again.";
    }else if (isset ($_GET['err']) && $_GET['err'] == 'false'){
    $errmsg = "An error occured while validating username and password. Your username and/or password is invalid. Please try again.";
    }
    echo "<p>".$errmsg."</p>";

    Is this statement cannot run in php5 ?

    the output return me with... "; ?>

    please help, thank you.

  2. #2
    SitePoint Addict jpease's Avatar
    Join Date
    Jul 2002
    Location
    In the network.
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if it will solve your problem, but I believe that should be "elseif" not "else if".

    http://us.php.net/elseif
    Last edited by jpease; Jul 11, 2007 at 08:05. Reason: typo

  3. #3
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code works in PHP5. Just make sure you put <?php and ?> on either side of the code.

    I have formatted the code a little bit so you can try this code:
    PHP Code:
    <?php
    if(isset($_GET['err']) && $_GET['err'] == 'true') {
      
    $errmsg 'An error occured while validating username and password. Some fields are left empty. Please try again."';
    }elseif(isset(
    $_GET['err']) && $_GET['err'] == 'false') {
      
    $errmsg 'An error occured while validating username and password. Your username and/or password is invalid. Please try again.';
    }
    echo 
    '<p>'.$errmsg.'</p>'
    ?>
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    done, Oh, i have to put <?php instead of <?.
    thank you.

  5. #5
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    In a house in the USA
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The <? is the shorthand (sloppy) code for starting PHP scripts or code. You will find that it is best to always use the <?php that way you do not have to worry about that setting.
    Daniel
    http://www.wlscripting.com - PHP Tutorials and code snippets
    Notepad++ Function List plugin tip - for PHP developers

  6. #6
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jpease View Post
    Not sure if it will solve your problem, but I believe that should be "elseif" not "else if".

    http://us.php.net/elseif
    "else if" is a valid means to write it (the way i prefer).

    In PHP, you can also write 'else if' (in two words) and the behavior would be identical to the one of 'elseif' (in a single word). The syntactic meaning is slightly different (if you're familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



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
  •