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 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2003
    Location
    Massachusetts
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    What is the difference between these statements?

    PHP Code:
    if(!isset($_POST["var"])){  }
    if(
    $_POST["var"]==""){  }
    if(!
    $_POST["var"]){  } 
    My question is, what is the difference between each one?

    I am using !isset($_POST["var"]) || $_POST["var"]=="" to see if they were not entered. I am doing this so that I can show an error, then return the form to the user.

    BUT, I have a feeling I could just get rid of one of them.
    Would the following two statements work the same?

    PHP Code:
    if(!isset($_POST["var"]) || $_POST["var"]==""){
    // Show error and form
    }

    if(
    $_POST["var"]==""){
    // Show error and form

    -Matt

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,095
    Thanks
    11
    Thanked 101 Times in 99 Posts
    in the context of checking for empty form fields, empty normally covers the bases...

    PHP Code:
    <?if( empty( $_POST['var'] ) ){}?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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