if statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Latio

    if statement

    I am trying to remember how you write an if statement to check if any value
    has been entered. For example seeing if a username has been entered in form.
    I have seen the following:

    if ($username == '')
    {
    print ("You've pressed submit without entering your username");
    }

    However is there another method which uses an exclamation mark? I am sure I
    have seen something for where $username has no value but I can't think what
    it was.

    Cheers

    Phil




  • Geoff Muldoon

    #2
    Re: if statement

    phil.latio@f-in-stupid.co.uk says...
    I am trying to remember how you write an if statement to check if any value
    has been entered. For example seeing if a username has been entered in form.
    I have seen the following:
    >
    if ($username == '')
    {
    print ("You've pressed submit without entering your username");
    }
    >
    However is there another method which uses an exclamation mark? I am sure I
    have seen something for where $username has no value but I can't think what
    it was.
    isSet ??

    if (!isSet($userna me)) { // do this if $username is not set

    GM

    Comment

    • Gordon Burditt

      #3
      Re: if statement

      >I am trying to remember how you write an if statement to check if any value
      >has been entered. For example seeing if a username has been entered in form.
      The variable $_GET['username'] or $_POST['username'] is where the
      input from a form element appears in a modern version of PHP, not $username.
      >I have seen the following:
      >
      >if ($username == '')
      >{
      print ("You've pressed submit without entering your username");
      >}
      >
      >However is there another method which uses an exclamation mark? I am sure I
      >have seen something for where $username has no value but I can't think what
      >it was.
      You can use isset($_GET['username']) to determine if the value was given
      at all.


      Comment

      • Phil Latio

        #4
        Re: if statement

        You can use isset($_GET['username']) to determine if the value was given
        at all.
        Yep. That was it. Thanks.

        Cheers

        Phil


        Comment

        • Phil Latio

          #5
          Re: if statement

          isSet ??
          >
          if (!isSet($userna me)) { // do this if $username is not set
          >
          GM
          Yep. That was it. Thanks.

          Cheers

          Phil


          Comment

          • Kimmo Laine

            #6
            Re: if statement

            "Geoff Muldoon" <geoff.muldoon@ trap.gmail.comw rote in message
            news:MPG.1fb969 feaad9fefe98987 f@news.readfree news.net...
            phil.latio@f-in-stupid.co.uk says...
            >I am trying to remember how you write an if statement to check if any
            >value
            >has been entered. For example seeing if a username has been entered in
            >form.
            >I have seen the following:
            >>
            >if ($username == '')
            >{
            > print ("You've pressed submit without entering your username");
            >}
            >>
            >However is there another method which uses an exclamation mark? I am sure
            >I
            >have seen something for where $username has no value but I can't think
            >what
            >it was.
            >
            isSet ??
            >
            if (!isSet($userna me)) { // do this if $username is not set

            If this is form validation, then isset won't do any good. The form field
            will be set, but it still may be empty. Better test that strlen() is greater
            than zero, or use empty(). And Of course, there's always the $username vs.
            $_POST['username'] issue. Seems like someone is using register_global s, for
            shame...

            --
            "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
            http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
            spam@outolempi. net | rot13(xvzzb@bhg byrzcv.arg)


            Comment

            • Phil Latio

              #7
              Re: if statement

              If this is form validation, then isset won't do any good. The form field
              will be set, but it still may be empty. Better test that strlen() is
              greater than zero, or use empty(). And Of course, there's always the
              $username vs. $_POST['username'] issue. Seems like someone is using
              register_global s, for shame...
              Not using register_global s but wish I had noticed your post earlier
              regarding the form validation issue. I assumed isset meant that it checked
              to see if it is actually set to something (had a value), not that it merely
              existed. Oh well.. it's all good learning.

              Cheers

              Phil


              Comment

              • Gordon Burditt

                #8
                Re: if statement

                >Not using register_global s but wish I had noticed your post earlier
                >regarding the form validation issue. I assumed isset meant that it checked
                >to see if it is actually set to something (had a value), not that it merely
                >existed. Oh well.. it's all good learning.
                A zero-length string is a real value. Whether or not you consider
                it to be an error, an unspecified value, or an explicitly specified
                value (the value when displaying the form might NOT be an empty
                string, it might be 'No Middle Initial' or the original value from
                the database record you're editing) depends on the variable,
                what it means, and the application.


                Comment

                Working...