undefined index

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • news.bigpond.com

    undefined index

    getting errors

    Notice: Undefined index: name in F:\uni\Software
    engineering\ass ignment4\guestb ook.php on line 6

    the variable $name is declared as $name = _POST["name"];

    What could be causing this?

    I've recently installed php 5 on IIS with mysql 4. All running on windows XP

    downloaded code straight from my uni's tute site.

    went to run it and it sort of runs but I get these errors at the top of the
    page.

    Thanks

    Karl.


  • nice.guy.nige

    #2
    Re: undefined index

    While the city slept, news.bigpond.co m (khmueller@bigp ond.com) feverishly
    typed...
    [color=blue]
    > getting errors
    >
    > Notice: Undefined index: name in F:\uni\Software
    > engineering\ass ignment4\guestb ook.php on line 6
    >
    > the variable $name is declared as $name = _POST["name"];[/color]

    Is this a typo in your post? Or does it appear *exactly* the same in your
    code? It should be $name = $_POST["name"];

    Cheers,
    Nige

    --
    Nigel Moss
    This is the personal website of Nigel Moss - Web and software developer, musician, photographer. It is home to my CV, portfolio, general info and more.

    Mail address not valid. nigel@DOG.nigen et.org.uk, take the DOG. out!
    In the land of the blind, the one-eyed man is very, very busy!


    Comment

    • kingofkolt

      #3
      Re: undefined index

      "news.bigpond.c om" <khmueller@bigp ond.com> wrote in message
      news:%nb1d.2904 5$D7.28671@news-server.bigpond. net.au...[color=blue]
      > getting errors
      >
      > Notice: Undefined index: name in F:\uni\Software
      > engineering\ass ignment4\guestb ook.php on line 6
      >
      > the variable $name is declared as $name = _POST["name"];
      >
      > What could be causing this?
      >
      > I've recently installed php 5 on IIS with mysql 4. All running on windows[/color]
      XP[color=blue]
      >
      > downloaded code straight from my uni's tute site.
      >
      > went to run it and it sort of runs but I get these errors at the top of[/color]
      the[color=blue]
      > page.
      >
      > Thanks
      >
      > Karl.
      >
      >[/color]

      In $_POST['name'], 'name' is the undefined index if no 'name' has been
      POSTed. For example, if you have a form whose action is itself, and in the
      form php file you refer to $_POST['name'], 'name' is undefined until the
      form is submitted.

      - JP


      Comment

      • Ian.H

        #4
        Re: undefined index

        On Mon, 13 Sep 2004 17:48:54 GMT, "kingofkolt "
        <jessepNOSPAM@c omcast.net> wrote:
        [color=blue]
        >"news.bigpond. com" <khmueller@bigp ond.com> wrote in message
        >news:%nb1d.290 45$D7.28671@new s-server.bigpond. net.au...[color=green]
        >> getting errors
        >>
        >> Notice: Undefined index: name in F:\uni\Software
        >> engineering\ass ignment4\guestb ook.php on line 6
        >>
        >> the variable $name is declared as $name = _POST["name"];
        >>
        >> What could be causing this?
        >>
        >> I've recently installed php 5 on IIS with mysql 4. All running on windows[/color]
        >XP[color=green]
        >>
        >> downloaded code straight from my uni's tute site.
        >>
        >> went to run it and it sort of runs but I get these errors at the top of[/color]
        >the[color=green]
        >> page.
        >>
        >> Thanks
        >>
        >> Karl.
        >>
        >>[/color]
        >
        >In $_POST['name'], 'name' is the undefined index if no 'name' has been
        >POSTed. For example, if you have a form whose action is itself, and in the
        >form php file you refer to $_POST['name'], 'name' is undefined until the
        >form is submitted.
        >
        >- JP
        >[/color]


        PHP5 requires some extra checks AFAIU. You'll now need to use code such
        as:


        if (isset($_POST['name'])) {
        /* do something with $_POST['name']... */
        } else {
        /* $_POST['name'] is undefined */
        }


        HTH =)



        Regards,

        Ian

        --
        Ian.H
        digiServ Network
        London, UK

        Comment

        • Daniel Tryba

          #5
          Re: undefined index

          Ian.H <ian@windozedig iserv.net> wrote:[color=blue]
          > if (isset($_POST['name'])) {
          > /* do something with $_POST['name']... */
          > } else {
          > /* $_POST['name'] is undefined */
          > }[/color]

          array_key_exist s would be better in general...

          From http://nl2.php.net/array_key_exists
          "Example 2. array_key_exist s() vs isset()

          isset() does not return TRUE for array keys that correspond to a NULL
          value, while array_key_exist s() does.
          <?php
          $search_array = array('first' => null, 'second' => 4);

          // returns false
          isset($search_a rray['first'])

          // returns true
          array_key_exist s('first', $search_array);
          ?>"

          The chance of null values in POST/GET is quite minimal though :)

          --

          Daniel Tryba

          Comment

          • Ian.H

            #6
            Re: undefined index

            On Mon, 13 Sep 2004 20:42:21 +0000 (UTC), Daniel Tryba
            <news_comp.lang .php@canopus.nl > wrote:
            [color=blue]
            >Ian.H <ian@windozedig iserv.net> wrote:[color=green]
            >> if (isset($_POST['name'])) {
            >> /* do something with $_POST['name']... */
            >> } else {
            >> /* $_POST['name'] is undefined */
            >> }[/color]
            >
            >array_key_exis ts would be better in general...
            >
            >From http://nl2.php.net/array_key_exists
            >"Example 2. array_key_exist s() vs isset()
            >
            >isset() does not return TRUE for array keys that correspond to a NULL
            >value, while array_key_exist s() does.
            ><?php
            >$search_arra y = array('first' => null, 'second' => 4);
            >
            >// returns false
            >isset($search_ array['first'])
            >
            >// returns true
            >array_key_exis ts('first', $search_array);
            >?>"
            >
            >The chance of null values in POST/GET is quite minimal though :)[/color]


            Ahh good point.. while true, you never know and if you can cater for
            it........... =)



            Regards,

            Ian

            --
            Ian.H
            digiServ Network
            London, UK

            Comment

            Working...