13 Replies Latest reply: Jan 22, 2009 5:03 AM by Newsgroup_User RSS

    Undefined errors on live site

    Stuart Haiz Community Member
      I developed a site on my server here: Test Site & everything worked as planned. As soon as I uploaded to the client's site, (
      client's site here) the top of the page was filled with errors like this:

      Notice: Undefined index: Department in E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 3
      Notice: Undefined index: maxprice in E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
      Notice: Undefined index: maxprice in E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
      Notice: Undefined index: maxprice in E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
      Notice: Undefined index: maxprice in E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
      Notice: Undefined index: maxprice in E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11

      I did a Google search & found some code that fixed this issue, but I'm not the developer & don't know what it means. The code:

      $ebits = ini_get('error_reporting');
      error_reporting($ebits ^ E_NOTICE);

      seems to have disabled error messages so I can't find out why the Quick Search is not working on this site. Again, it works in my test site at my domain. (The Quick Search posts to a results page with an iframe.) Either the php is not being sent or there is another issue which I really can't solve without help please!
        • 1. Re: Undefined errors on live site
          Newsgroup_User Community Member
          Your page is referring to variables that have not yet received a value -

          $Department on line 3
          $maxprice on line 11

          and so on. Finding a snippet of code is not the solution. Fixing the use
          of the variables before they have been given a value is the solution. Can
          we see your code?

          --
          Murray --- ICQ 71997575
          Adobe Community Expert
          (If you *MUST* email me, don't LAUGH when you do so!)
          ==================
          http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
          http://www.dwfaq.com - DW FAQs, Tutorials & Resources
          ==================


          "Sirius7" <webforumsuser@macromedia.com> wrote in message
          news:gl5tmo$mg$1@forums.macromedia.com...
          >I developed a site on my server here:
          > http://www.designermagic.co.uk/hobarts/index.php & everything worked as
          > planned. As soon as I uploaded to the client's site, (
          > http://www.hobarts.co.uk) the top of the page was filled with errors like
          > this:
          >
          > Notice: Undefined index: Department in
          > E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 3
          > Notice: Undefined index: maxprice in
          > E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
          > Notice: Undefined index: maxprice in
          > E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
          > Notice: Undefined index: maxprice in
          > E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
          > Notice: Undefined index: maxprice in
          > E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
          > Notice: Undefined index: maxprice in
          > E:\domains\h\hobarts.co.uk\user\htdocs\index.php on line 11
          >
          > I did a Google search & found some code that fixed this issue, but I'm not
          > the
          > developer & don't know what it means. The code:
          >
          > $ebits = ini_get('error_reporting');
          > error_reporting($ebits ^ E_NOTICE);
          >
          > seems to have disabled error messages so I can't find out why the Quick
          > Search
          > is not working on this site. Again, it works in my test site at my domain.
          > (The
          > Quick Search posts to a results page with an iframe.) Either the php is
          > not
          > being sent or there is another issue which I really can't solve without
          > help
          > please!
          >

          • 2. Re: Undefined errors on live site
            Stuart Haiz Community Member
            Hi Murray

            Thanks. I realise the sense in what you are saying! Here's some of my code from the top of the file (minus the code 'fix').

            <?php
            /* RENT OPTION */
            if($_GET['Department'] == 3){
            $_GET['minprice'] = '';
            $_GET['maxprice'] = '';
            }

            /* The Options Strings for prices */
            $rent_minprice = '<label for="PriceMin">Price Min:<select name="minprice" id="MinPrice"><option value=""></option></select></label>';
            /*Rent is disabled if selected so no value assigned - for use on results.php*/
            $rent_maxprice = '<label for="PriceMax">Price Max:<select name="maxprice" id="MaxPrice"><option value="150" ' . (($_GET['maxprice'] == 150)?'selected':'') . '>&pound;150pw</option><option value="250" ' . (($_GET['maxprice'] == 250)?'selected':'') . '>&pound;250pw</option><option value="350" ' . (($_GET['maxprice'] == 350)?'selected':'') . '>&pound;350pw</option><option value="450" ' . (($_GET['maxprice'] == 450)?'selected':'') . '>&pound;450pw</option><option value="550" ' . (($_GET['maxprice'] == 550)?'selected':'') . '>&pound;550pw</option><option value="">No Maximum</option></select></label>';

            Then I have variables for $buy_minprice & $buy_maxprice.

            The url for the iframe on the results page once the form is posted is:
            " http://powering.expertagent.co.uk/customsearch.aspx?aid={f7863a23-aa92-45ed-aef6-b5cc6ac33 4c7}&showsearchfirst=false&dep=<?php echo $_GET['Department'];?>&minbeds=<?php echo $_GET['bedrooms'];?>&minprice=<?php echo $_GET['minprice'];?>&maxprice=<?php echo $_GET['maxprice'];?>&districts=<?php echo $_GET['districts'];?>&regions=583358345835&currencycode=GBP&sort=Desc&areas=<?php echo implode(',', $_GET['areas']);?>&types=<?php echo $_GET['types'];?>&commercialtypes=<?php echo $_GET['commercialtypes'];?>"

            Thanks in advance.
            • 3. Re: Undefined errors on live site
              Stuart Haiz Community Member
              Hi Murray

              This has been fixed now. It was solved with a .htaccess file to turn off error reporting on the live server. (Site is on shared hosting with errors on & no control over php.ini, so also going to be moving to new web host!)

              Thanks for the advice.
              • 4. Re: Undefined errors on live site
                Newsgroup_User Community Member
                So, you solved it with a sledgehammer, not a finishing hammer? 8)

                You could have just initialized all those variables at the top of the page
                with -

                $variable1 = $variable2 = $variable3 = '';

                and that would do the trick....

                --
                Murray --- ICQ 71997575
                Adobe Community Expert
                (If you *MUST* email me, don't LAUGH when you do so!)
                ==================
                http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                ==================


                "Sirius7" <webforumsuser@macromedia.com> wrote in message
                news:gl74gf$fa3$1@forums.macromedia.com...
                > Hi Murray
                >
                > This has been fixed now. It was solved with a .htaccess file to turn off
                > error
                > reporting on the live server. (Site is on shared hosting with errors on &
                > no
                > control over php.ini, so also going to be moving to new web host!)
                >
                > Thanks for the advice.
                >

                • 5. Re: Undefined errors on live site
                  Newsgroup_User Community Member
                  .oO(Sirius7)

                  > This has been fixed now. It was solved with a .htaccess file to turn off error
                  >reporting on the live server.

                  This doesn't solve the problem. Your script still has bugs.

                  Ignoring notices can lead to real problems - from nasty and hard-to-find
                  bugs to really big security holes. You definitely want to fix the issues
                  instead of just turning of the warnings.

                  Micha
                  • 6. Re: Undefined errors on live site
                    Stuart Haiz Community Member
                    A web.config file has also been added to switch off custom errors.
                    Murray, $rent_minprice = $rent_maxprice = $buy_minprice = $buy_maxprice = ''; didn't solve the undefined index problem. Messages reappeared when I tried this. Seems the sledgehammer is my most understood tool at this stage...

                    Micha - I agree with the comment that you can't put your head in the sand. I'm the designer & am handing this over to a developer who knows what he is doing!
                    • 7. Re: Undefined errors on live site
                      Newsgroup_User Community Member
                      > Murray, $rent_minprice = $rent_maxprice = $buy_minprice = $buy_maxprice =
                      > '';
                      > didn't solve the undefined index problem. Messages reappeared when I tried
                      > this.

                      Do the messages include any of these variable names? As I recall there were
                      several other variables that would need to be added to this list, like
                      $Department, and $maxprice. Add them and see what happens.

                      --
                      Murray --- ICQ 71997575
                      Adobe Community Expert
                      (If you *MUST* email me, don't LAUGH when you do so!)
                      ==================
                      http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                      http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                      ==================


                      "Sirius7" <webforumsuser@macromedia.com> wrote in message
                      news:gl77hs$iuc$1@forums.macromedia.com...
                      >A web.config file has also been added to switch off custom errors.
                      > Murray, $rent_minprice = $rent_maxprice = $buy_minprice = $buy_maxprice =
                      > '';
                      > didn't solve the undefined index problem. Messages reappeared when I tried
                      > this. Seems the sledgehammer is my most understood tool at this stage...
                      >
                      > Micha - I agree with the comment that you can't put your head in the sand.
                      > I'm
                      > the designer & am handing this over to a developer who knows what he is
                      > doing!
                      >

                      • 8. Undefined errors on live site
                        Stuart Haiz Community Member
                        Correct. Department, minprice & maxprice are all names for my labels. I tried this too, without luck:

                        $rent_minprice = $rent_maxprice = $buy_minprice = $buy_maxprice = $Department = $minprice = $maxprice = '';

                        It returned this:

                        Notice: Undefined index: Department in E:\domains\h\hobarts.co.uk\user\htdocs\HIPs.php on line 6
                        Notice: Undefined index: maxprice in E:\domains\h\hobarts.co.uk\user\htdocs\HIPs.php on line 13
                        (plus a few more variants including the minprice.)

                        At the top of my code I have this, causing the messages:
                        if($_GET['Department'] == 3){
                        $_GET['minprice'] = '';
                        $_GET['maxprice'] = '';
                        }

                        This is followed by my variables like this:
                        $buy_minprice = '<label for="PriceMin">Price Min:<select name="minprice" id="MinPrice"><option ' . ( ($_GET['minprice'] == 0)?'selected':'') . ' value="0">No Minimum</option><option ' . ( ($_GET['minprice'] == 150000)?'selected':'') . ' value="150000">&pound;150,000</option><option ' . ( ($_GET['minprice'] == 250000)?'selected':'') . ' value="250000">&pound;250,000</option><option ' . ( ($_GET['minprice'] == 350000)?'selected':'') . ' value="350000">&pound;350,000</option><option ' . ( ($_GET['minprice'] == 500000)?'selected':'') . ' value="500000">&pound;500,000</option><option ' . ( ($_GET['minprice'] == 750000)?'selected':'') . ' value="750000">&pound;750,000</option></select></label>';

                        Thanks Murray for your time looking at this.
                        • 9. Re: Undefined errors on live site
                          Newsgroup_User Community Member
                          .oO(Murray *ACE*)

                          >> Murray, $rent_minprice = $rent_maxprice = $buy_minprice = $buy_maxprice =
                          >> '';
                          >> didn't solve the undefined index problem. Messages reappeared when I tried
                          >> this.
                          >
                          >Do the messages include any of these variable names? As I recall there were
                          >several other variables that would need to be added to this list, like
                          >$Department, and $maxprice. Add them and see what happens.

                          Shouldn't change anything, because the error message refers to undefined
                          array indexes, not variables. For example this line

                          if($_GET['Department'] == 3){

                          will throw a notice if no such URL parameter was passed to the site. The
                          solution is to first check with isset() to see if the parameter exists,
                          e.g.

                          if (isset($_GET['Department']) && $_GET['Department'] == 3) {

                          Micha
                          • 10. Re: Undefined errors on live site
                            Stuart Haiz Community Member
                            Micha
                            This clears the first message about the department, so I get the maxprice & minprice messages on their own now:

                            Notice: Undefined index: maxprice in E:\domains\h\hobarts.co.uk\user\htdocs\HIPs.php on line 13
                            • 11. Re: Undefined errors on live site
                              Newsgroup_User Community Member
                              .oO(Sirius7)

                              >Micha
                              > This clears the first message about the department, so I get the maxprice &
                              >minprice messages on their own now:
                              >
                              > Notice: Undefined index: maxprice in
                              >E:\domains\h\hobarts.co.uk\user\htdocs\HIPs.php on line 13

                              Same thing, same problem, same solution. Before accessing these
                              parameters use isset() to see if they exists. If not, use some default
                              value.

                              Additionally you should _not_ write to the $_GET array, but consider it
                              read-only. This means that you should check and load all URL parameters
                              you need into local variables. This also allows to easily define default
                              values if some parameter is missing, e.g.

                              $minPrice = isset($_GET['minprice']) ? $_GET['minprice'] : 0;

                              (This is short syntax for an if-then-else statement, called ternary
                              operator.)

                              This will always give you a defined value for the $minPrice variable
                              (either the user-submitted value or your own default) which you can
                              reliably work with. Same for max price and other parameters.

                              Micha
                              • 12. Re: Undefined errors on live site
                                Stuart Haiz Community Member
                                Micha

                                Thank you for your help with this - & also for helping me to learn some important stuff here too. I'm going to try this on a test page this evening when I get home & hopefully, post some good news tomorrow.

                                Thanks again.
                                • 13. Re: Undefined errors on live site
                                  Newsgroup_User Community Member
                                  D'oh. Right string, but wrong yoyo, as they say.

                                  --
                                  Murray --- ICQ 71997575
                                  Adobe Community Expert
                                  (If you *MUST* email me, don't LAUGH when you do so!)
                                  ==================
                                  http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                                  http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                                  ==================


                                  "Michael Fesser" <netizen@gmx.de> wrote in message
                                  news:13gen4h8m04om5udjmisq93luc4tk484dd@4ax.com...
                                  > .oO(Murray *ACE*)
                                  >
                                  >>> Murray, $rent_minprice = $rent_maxprice = $buy_minprice = $buy_maxprice
                                  >>> =
                                  >>> '';
                                  >>> didn't solve the undefined index problem. Messages reappeared when I
                                  >>> tried
                                  >>> this.
                                  >>
                                  >>Do the messages include any of these variable names? As I recall there
                                  >>were
                                  >>several other variables that would need to be added to this list, like
                                  >>$Department, and $maxprice. Add them and see what happens.
                                  >
                                  > Shouldn't change anything, because the error message refers to undefined
                                  > array indexes, not variables. For example this line
                                  >
                                  > if($_GET['Department'] == 3){
                                  >
                                  > will throw a notice if no such URL parameter was passed to the site. The
                                  > solution is to first check with isset() to see if the parameter exists,
                                  > e.g.
                                  >
                                  > if (isset($_GET['Department']) && $_GET['Department'] == 3) {
                                  >
                                  > Micha