SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there a better way to do this?

    Here is what I have now:
    PHP Code:
    <?

    // check to see if the form is completed

    if ($first_name==""); {

    echo(
    "You need to provide your first name!");

    }

    elseif (
    $last_name==""); {

    echo(
    "You need to provide your last name!");

    }

    ?>
    I've seen some simplify this code using these... ||

    Can someone show me how to do it?

    Thanks

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:

    PHP Code:
    <?php
    if(($firstname == "") || ($lastname == "")) {
    echo 
    "You need to provide your first name!";
    }
    ?>
    The || is means 'or'.

    -Peter

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simpler you can just do...

    PHP Code:
    <?php
    if(($firstname == "") or ($lastname == "")) {
    echo 
    "You need to provide your first name!";
    }
    ?>
    Or = || = Or
    And = && = And

  4. #4
    VICTORY IS MINE! luchazard's Avatar
    Join Date
    May 2001
    Location
    USA
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awsome! That post helped me soooo much


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
  •