Undefined Index Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ridgedale
    New Member
    • Oct 2007
    • 27

    Undefined Index Error

    I wonder if anyone can help resolve an issue I've come across in making a customer's website live when it has tested fine in my own hosting space.

    I am getting the following errors: Notice: Undefined index: vartalk

    For reference I provide the following links:

    My hosting space (where everything appears to be working fine):


    My customer's hosting space (where the php code is breaking down):


    Does anyone have any ideas how I resolve this?

    Thanks in advance.
  • ridgedale
    New Member
    • Oct 2007
    • 27

    #2
    Could it be the fact that my hosting space is running on the Debian Linux platform and is running PHP version 4.4.6 and the customer's hosting space is running on the Windows platform and is running PHP version 5.0.4 that this issue has arisen?

    Does anyone have any ideas how I might fix this?

    Thanks again.

    Comment

    • ridgedale
      New Member
      • Oct 2007
      • 27

      #3
      It can't be the version of PHP as I am running version 5.1.6 locally and the files are displaying correctly.

      Thanks again.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hi.

        Could you show us the code that is generating the error?

        It is unlikely (yet possible) that your PHP4 code is failing on a PHP5 server. If it were reversed, however, it would be a different story.

        There is of course a possibility that your servers are configured differently, but until we see the code it is hard to guess what difference that may be.

        Comment

        • ridgedale
          New Member
          • Oct 2007
          • 27

          #5
          I managed to fix the problem that only occurs on a Windows based server by adding an @ symbol in front of each occurence of the $_GET['vartalk'] in the nav.php file which resolved any associated issues with the vartalk variable.

          I also noticed once having fixed that issue that the request form was also broken on the Windows platform. It appears that Linux based servers either know how to deal with non-declared variables and Windows based servers don't. Is that a fair summary?

          Thanks again.

          Comment

          • ridgedale
            New Member
            • Oct 2007
            • 27

            #6
            Sorry, Atli. I missed your reply. Below is the associated code for the nav.php file with that @ symbol inserted which resolved the initial issue:

            [code=php] <div id="sbx_nav">

            <?php

            $myitem = @$_GET['vartalk'];

            if(@$_GET['vartalk'] == "1"):
            $myitem = '&raquo; Practice Based Innovation';

            elseif(@$_GET['vartalk'] == "2"):
            $myitem = '&raquo; Sustainability< br>&nbsp;&nbsp; &nbsp;A Question of Branding';

            elseif(@$_GET['vartalk'] == "3"):
            $myitem = '&raquo; Experiential Branding<br>&nb sp;&nbsp;&nbsp; Death of Banality<br><sp an class="indent2" >Birth of Experience</span>';

            elseif(@$_GET['vartalk'] == "4"):
            $myitem = '&raquo; Portable Inhalers';

            elseif(@$_GET['vartalk'] == "5"):
            $myitem = '&raquo; The Packaging 7f’s';

            elseif(@$_GET['vartalk'] == "6"):
            $myitem = '&raquo; US Package Design Magazine<br>&nb sp;&nbsp;&nbsp; Makeover Challenge';

            elseif(@$_GET['vartalk'] == "7"):
            $myitem = '&raquo; Innovation<br>& nbsp;&nbsp;&nbs p;Managing Uncertainty';

            endif; ?>

            <p><a href="sbx_pract ice.php?vartalk =1">

            <?php
            if(@$_GET['vartalk'] == "1"):
            echo $myitem;
            else:
            echo '&nbsp;&nbsp;&n bsp;Practice Based Innovation';
            endif; ?>

            </a></p>

            <p><a href="sbx_susta in.php?vartalk= 2">

            <?php
            if(@$_GET['vartalk'] == "2"):
            echo $myitem;
            else:
            echo '&nbsp;&nbsp;&n bsp;Sustainabil ity<br>&nbsp;&n bsp;&nbsp;A Question of Branding';
            endif; ?>

            </a></p>

            <p><a href="sbx_expbr and.php?vartalk =3">

            <?php
            if(@$_GET['vartalk'] == "3"):
            echo $myitem;
            else:
            echo '&nbsp;&nbsp;&n bsp;Experientia l Branding<br>&nb sp;&nbsp;&nbsp; Death of Banality<br><sp an class="indent"> Birth of Experience</span>';
            endif; ?>

            </a></p>

            <p><a href="sbx_inhal ers.php?vartalk =4">

            <?php
            if(@$_GET['vartalk'] == "4"):
            echo $myitem;
            else:
            echo '&nbsp;&nbsp;&n bsp;Portable Inhalers';
            endif; ?>

            </a></p>

            <p><a href="sbx_seven fs.php?vartalk= 5">

            <?php
            if(@$_GET['vartalk'] == "5"):
            echo $myitem;
            else:
            echo '&nbsp;&nbsp;&n bsp;The Packaging 7f\'s';
            endif; ?>

            </a></p>

            <p><a href="sbx_makeo ver.php?vartalk =6">

            <?php
            if(@$_GET['vartalk'] == "6"):
            echo $myitem;
            else:
            echo '&nbsp;&nbsp;&n bsp;US Package Design Magazine<br>&nb sp;&nbsp;&nbsp; Makeover Challenge';
            endif; ?>

            </a></p>

            <p class="lastlink "><a href="sbx_innov ation.php?varta lk=7">

            <?php
            if(@$_GET['vartalk'] == "7"):
            echo $myitem;
            else:
            echo '&nbsp;&nbsp;&n bsp;Innovation< br>&nbsp;&nbsp; &nbsp;Managi ng Uncertainty';
            endif; ?>

            </a></p>

            </div>[/code]

            Thanks again.
            Last edited by Atli; Oct 9 '07, 06:41 PM. Reason: Changed [html] tags to [code=php] tags.

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              Ok, now I see.

              The problem has nothing to do with the platform on which your servers are running.

              This error is in fact not an error. It is a Warning.
              Your code can execute without problems even if you get shown a warning.

              The Windows server, which is showing the error has the debug messages turned on, the Linux server apparently does not. So all errors on your Linux server are being suppressed, in order to hide them from your clients.

              Adding a @ sign to a function will, in most cases, suppress warnings. This is not advisable however, as this can suppress errors that may help you debug your code. It is better to complete the code without any suppressing errors and disable the debug messages when putting the web on a live server.

              The warning you are being shown is shown when you try to access an array element or a variable that does not exists. In your case you are trying to access an element of the $_GET super-global that has not been sent.

              To avoid this warning, try formatting you code somewhat like this:
              [code=php]
              if(isset($_GET['element'])) {
              $element = $_GET['element'];
              # Input validation would not be a bad idea either!

              if($element < 5) {
              echo "Element is less than 5";
              }
              else if($elemet > 5) {
              echo "Element is greater than 5";
              }
              else {
              echo "Element is 5!";
              }
              }
              else {
              echo "GET variable 'element' was not passed!";
              }
              [/code]

              Comment

              • ridgedale
                New Member
                • Oct 2007
                • 27

                #8
                Atli, thanks for explaining this for me.

                Much appreciated.

                Comment

                Working...