CHecking variable Existence

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

    CHecking variable Existence

    Hey guys, I want to PHP to do stuff only if a sertain form variable exists.
    How do i check to see if a variable exists or not?

    Something like If $http_post_vars['name'] exists, then do this.

    syntax please? :)


  • Geoff Berrow

    #2
    Re: CHecking variable Existence

    I noticed that Message-ID: <OfvZb.5860$J84 .5476@fe1.texas .rr.com> from
    Tesla contained the following:
    [color=blue]
    >Something like If $http_post_vars['name'] exists, then do this.
    >
    >syntax please? :)[/color]

    yes. :)


    if($http_post_v ars['name']){do this}



    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Jedi121

      #3
      Re: CHecking variable Existence

      Geoff Berrow a écrit le 20/02/2004 :[color=blue][color=green]
      >> Something like If $http_post_vars['name'] exists, then do this.
      >>
      >> syntax please? :)[/color]
      >
      > yes. :)
      >
      >
      > if($http_post_v ars['name']){do this}[/color]

      I prefer using isset() function : http://www.php.net/isset


      Comment

      • Garrett Albright

        #4
        Re: CHecking variable Existence

        In article <mesnews.a83c7d 42.89c625b7.549 .2689@free.fr.R emovethis>,
        Jedi121 <jedi121news@fr ee.fr.Removethi s> wrote:
        [color=blue][color=green]
        > > if($http_post_v ars['name']){do this}[/color]
        >
        > I prefer using isset() function : http://www.php.net/isset[/color]

        I have a similar issue as the first poster.

        isset($_POST['name']) works, as does if ($_POST['name']!=NULL) . The
        problem is that, if error_reporting is set to E_ALL, both of those will
        pop up an error that says "Notice: Undefined index: name" at the top of
        the page. Yes, you can make that go away by setting error_reporting to
        ignore Notices, but when I'm testing scripts I like to keep it on E_ALL
        so I know if I'm doing something that's not fatal but still stupid.

        So is there a way to check for a variable's existence without PHP
        whining if it doesn't exist? :P

        if ($POST['name']) seems to always evaluate as true in my tests -- as
        well as pop up a Notice.

        Comment

        • Matthias Esken

          #5
          Re: CHecking variable Existence

          Garrett Albright <g_m_albr-nospam-ight@ya-nospam-hoo.com> schrieb:
          [color=blue]
          > isset($_POST['name']) works, as does if ($_POST['name']!=NULL) . The
          > problem is that, if error_reporting is set to E_ALL, both of those will
          > pop up an error that says "Notice: Undefined index: name" at the top of
          > the page.[/color]

          isset($_POST['name']) shouldn't give a notice. Please recheck that.

          Regards,
          Matthias

          Comment

          • Garrett Albright

            #6
            Re: CHecking variable Existence

            In article <c1ae4f.1nc.1@u senet.esken.de> ,
            Matthias Esken <muelleimer2004 nospam@usenetve rwaltung.org> wrote:
            [color=blue]
            > isset($_POST['name']) shouldn't give a notice. Please recheck that.[/color]

            Recheck I did, and it did not give a notice. I must have had an error
            elsewhere in the code. My bad. :/

            Comment

            Working...