Undefinded index using $_POST ...

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

    Undefinded index using $_POST ...

    Hello, I'm just getting starting in php and MySQL and I've got my
    application working correctly on my local windows XP computer. Now, when I
    publish to my ISP it's not going so well, which is also a Windows server.

    I'm using form variables to control navigating to different pages when a
    page is reloaded. As I said no problem on my machine but on the ISP server
    I'm getting the following messages snd of course it's not working. Both
    systems are running php version 4.3.10.

    Thank you for any help provided because I'm really stumped!

    Vic


    Notice: Undefined index: Home in
    d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 11
    Notice: Undefined index: Clear in
    d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 14
    Notice: Undefined index: Update in
    d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 16
    Notice: Undefined variable: button in
    d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 24
    Notice: Undefined index: do in
    d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 187



    if ($_POST['Home'])
    {
    $button = "Home"; }
    else if ($_POST['Clear']) {
    $button = "Clear"; }
    else if ($_POST['Update']) {
    $button = "Update"; }

    switch ($button)
    {
    case "Clear":
    if (isset($selecte dRow))
    unset ($selectedRow);
    $items = 1;
    $street2 = " ";
    $comments= " ";
    $OriginAirport= "PDX";
    $searchState = "Oregon";
    $message_new = "New Item? Please complete following fields:";
    include("BagDet ail_form.inc");
    break;

    case "Home":
    // Load the Home Page
    $_SESSION['auth']="yes";
    $_SESSION['logname'] = $newname;
    header("Locatio n: index.php");
    break;

    case "Update":

    foreach($_POST as $field => $value)
    {
    if ($field != "email" and $field !="street2" and $field
    !="comments")
  • Erwin Moller

    #2
    Re: Undefinded index using $_POST ...

    Vic Spainhower wrote:

    Hi Vic,
    [color=blue]
    > Hello, I'm just getting starting in php and MySQL and I've got my
    > application working correctly on my local windows XP computer. Now, when I
    > publish to my ISP it's not going so well, which is also a Windows server.
    >
    > I'm using form variables to control navigating to different pages when a
    > page is reloaded. As I said no problem on my machine but on the ISP server
    > I'm getting the following messages snd of course it's not working. Both
    > systems are running php version 4.3.10.
    >
    > Thank you for any help provided because I'm really stumped!
    >
    > Vic
    >
    >
    > Notice: Undefined index: Home in
    > d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 11
    > Notice: Undefined index: Clear in
    > d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 14
    > Notice: Undefined index: Update in
    > d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 16
    > Notice: Undefined variable: button in
    > d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 24
    > Notice: Undefined index: do in
    > d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 187
    >
    >
    >
    > if ($_POST['Home'])[/color]

    Alway use:
    if (isset($_POST["home"]))

    to check if a a variable (in an array or not) exists.

    I think if you rewrite your code accordingly, you are out of notices.
    :-)

    Good luck!

    Regards,
    Erwin Moller

    Comment

    • Vic Spainhower

      #3
      Re: Undefinded index using $_POST ...

      Erwin,

      Thank you very much that was the problem! Would it be the error reporting
      level is different between my system and my ISP's server which is why it
      appeared to work on my system?

      Thanks,

      Vic


      "Erwin Moller"
      <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
      message news:42370be5$0 $28978$e4fe514c @news.xs4all.nl ...[color=blue]
      > Vic Spainhower wrote:
      >
      > Hi Vic,
      >[color=green]
      >> Hello, I'm just getting starting in php and MySQL and I've got my
      >> application working correctly on my local windows XP computer. Now, when
      >> I
      >> publish to my ISP it's not going so well, which is also a Windows server.
      >>
      >> I'm using form variables to control navigating to different pages when a
      >> page is reloaded. As I said no problem on my machine but on the ISP
      >> server
      >> I'm getting the following messages snd of course it's not working. Both
      >> systems are running php version 4.3.10.
      >>
      >> Thank you for any help provided because I'm really stumped!
      >>
      >> Vic
      >>
      >>
      >> Notice: Undefined index: Home in
      >> d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 11
      >> Notice: Undefined index: Clear in
      >> d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 14
      >> Notice: Undefined index: Update in
      >> d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 16
      >> Notice: Undefined variable: button in
      >> d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line 24
      >> Notice: Undefined index: do in
      >> d:\html\users\1 49999\mydomainc om\html\myfolde r\Member_Page.p hp on line
      >> 187
      >>
      >>
      >>
      >> if ($_POST['Home'])[/color]
      >
      > Alway use:
      > if (isset($_POST["home"]))
      >
      > to check if a a variable (in an array or not) exists.
      >
      > I think if you rewrite your code accordingly, you are out of notices.
      > :-)
      >
      > Good luck!
      >
      > Regards,
      > Erwin Moller[/color]


      Comment

      • Michael Fesser

        #4
        Re: Undefinded index using $_POST ...

        .oO(Vic Spainhower)
        [color=blue]
        >Thank you very much that was the problem! Would it be the error reporting
        >level is different between my system and my ISP's server which is why it
        >appeared to work on my system?[/color]

        Yep. The default error_reporting doesn't show notices. You should set it
        to E_ALL in your php.ini.

        Micha

        Comment

        • Kenneth Downs

          #5
          Re: Undefinded index using $_POST ...

          Erwin Moller wrote:
          [color=blue][color=green]
          >>
          >>
          >> if ($_POST['Home'])[/color]
          >
          > Alway use:
          > if (isset($_POST["home"]))
          >
          > to check if a a variable (in an array or not) exists.
          >
          > I think if you rewrite your code accordingly, you are out of notices.
          > :-)
          >[/color]

          ....and to go further, you can wrap it:

          function PostSafe($key,$ default="",$rep ort_bad_key=tru e) {
          if (isset($_POST[$key])) { return MySanitizer($_P OST[$key]); }

          if ($report_bad_ke y) {
          ErrorAdd("Attem pt to retrieve non-existent post key: $key");
          }
          return $default;
          }

          so a normal call is:

          $home = PostSafe("Home" );

          and you can also provide a default and suppress error reporting on optional
          values:

          $myvar = PostSafe("optio nal_variable"," default_value", false);

          --
          Kenneth Downs
          Secure Data Software, Inc.
          (Ken)nneth@(Sec )ure(Dat)a(.com )

          Comment

          • Chung Leong

            #6
            Re: Undefinded index using $_POST ...

            "Vic Spainhower" <vic@showsec.co m> wrote in message
            news:IJidnVcrNI iAmqrfRVn-qQ@comcast.com. ..[color=blue]
            > Hello, I'm just getting starting in php and MySQL and I've got my
            > application working correctly on my local windows XP computer. Now, when I
            > publish to my ISP it's not going so well, which is also a Windows server.
            >
            > I'm using form variables to control navigating to different pages when a
            > page is reloaded. As I said no problem on my machine but on the ISP server
            > I'm getting the following messages snd of course it's not working. Both
            > systems are running php version 4.3.10.
            >
            > Thank you for any help provided because I'm really stumped![/color]

            Just stick a @ in front of $_POST[] to supress the notice:

            if(@$_POST['Home']) {
            }


            Comment

            • Erwin Moller

              #7
              Re: Undefinded index using $_POST ...

              Chung Leong wrote:
              [color=blue]
              > "Vic Spainhower" <vic@showsec.co m> wrote in message
              > news:IJidnVcrNI iAmqrfRVn-qQ@comcast.com. ..[color=green]
              >> Hello, I'm just getting starting in php and MySQL and I've got my
              >> application working correctly on my local windows XP computer. Now, when
              >> I publish to my ISP it's not going so well, which is also a Windows
              >> server.
              >>
              >> I'm using form variables to control navigating to different pages when a
              >> page is reloaded. As I said no problem on my machine but on the ISP
              >> server I'm getting the following messages snd of course it's not working.
              >> Both systems are running php version 4.3.10.
              >>
              >> Thank you for any help provided because I'm really stumped![/color]
              >
              > Just stick a @ in front of $_POST[] to supress the notice:
              >
              > if(@$_POST['Home']) {
              > }[/color]

              Yes, it supresses the error, but I do not like that approach.
              IMHO it is better to branch your code, so you know if the posting contains
              the things you expect.

              But it will depend on the situation if you get away with it.

              (Just my 2 cents, I am not saying you are wrong.)

              Regards,
              Erwin Moller

              Comment

              • Geoff Berrow

                #8
                Re: Undefinded index using $_POST ...

                I noticed that Message-ID: <4237fb7c$0$289 75$e4fe514c@new s.xs4all.nl>
                from Erwin Moller contained the following:
                [color=blue][color=green]
                >> if(@$_POST['Home']) {
                >> }[/color]
                >
                >Yes, it supresses the error, but I do not like that approach.
                >IMHO it is better to branch your code, so you know if the posting contains
                >the things you expect.[/color]


                I suspect Chung is being playful
                --
                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

                • Chung Leong

                  #9
                  Re: Undefinded index using $_POST ...

                  "Erwin Moller"
                  <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
                  message news:4237fb7c$0 $28975$e4fe514c @news.xs4all.nl ...[color=blue]
                  > Chung Leong wrote:
                  >[color=green]
                  > > "Vic Spainhower" <vic@showsec.co m> wrote in message
                  > > news:IJidnVcrNI iAmqrfRVn-qQ@comcast.com. ..[color=darkred]
                  > >> Hello, I'm just getting starting in php and MySQL and I've got my
                  > >> application working correctly on my local windows XP computer. Now,[/color][/color][/color]
                  when[color=blue][color=green][color=darkred]
                  > >> I publish to my ISP it's not going so well, which is also a Windows
                  > >> server.
                  > >>
                  > >> I'm using form variables to control navigating to different pages when[/color][/color][/color]
                  a[color=blue][color=green][color=darkred]
                  > >> page is reloaded. As I said no problem on my machine but on the ISP
                  > >> server I'm getting the following messages snd of course it's not[/color][/color][/color]
                  working.[color=blue][color=green][color=darkred]
                  > >> Both systems are running php version 4.3.10.
                  > >>
                  > >> Thank you for any help provided because I'm really stumped![/color]
                  > >
                  > > Just stick a @ in front of $_POST[] to supress the notice:
                  > >
                  > > if(@$_POST['Home']) {
                  > > }[/color]
                  >
                  > Yes, it supresses the error, but I do not like that approach.
                  > IMHO it is better to branch your code, so you know if the posting contains
                  > the things you expect.[/color]

                  Notices and warnings are not error. They're advisory messages that indicate
                  the *possibility* of a programming error. If triggered by something that
                  done by design, then they should simply be ignored. There is no point in
                  coding around false positives.

                  In this case, the absence of the field 'Home' is expected (hence the if
                  statement), so it is not a programming error.


                  Comment

                  Working...