SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2012
    Location
    Reading, England, United Kingdom
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Notice: Undefined index: func in C:\xampp\htdocs\5\three-tier\func.php on line 21

    Hi
    Can you please help me with this error
    Notice: Undefined index: func in C:\xampp\htdocs\5\three-tier\func.php on line 21

    Notice: Undefined index: func in C:\xampp\htdocs\5\three-tier\func.php on line 61

    i am getting this when i run this code


    PHP Code:
    <?php
    //**************************************
    //     Page load dropdown results     //
    //**************************************
    function getTierOne()
    {
        
    $result mysql_query("SELECT DISTINCT tier_one FROM three_drops"
        or die(
    mysql_error());

          while(
    $tier mysql_fetch_array$result )) 
      
            {
               echo 
    '<option value="'.$tier['tier_one'].'">'.$tier['tier_one'].'</option>';
            }

    }

    //**************************************
    //     First selection results     //
    //**************************************
    if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 
       
    drop_1($_GET['drop_var']); 
    }

    function 
    drop_1($drop_var)
    {  
        include_once(
    'db.php');
        
    $result mysql_query("SELECT DISTINCT tier_two FROM three_drops WHERE tier_one='$drop_var'"
        or die(
    mysql_error());
        
        echo 
    '<select name="drop_2" id="drop_2">
              <option value=" " disabled="disabled" selected="selected">Choose one</option>'
    ;

               while(
    $drop_2 mysql_fetch_array$result )) 
                {
                  echo 
    '<option value="'.$drop_2['tier_two'].'">'.$drop_2['tier_two'].'</option>';
                }
        
        echo 
    '</select>';
        echo 
    "<script type=\"text/javascript\">
    $('#wait_2').hide();
        $('#drop_2').change(function(){
          $('#wait_2').show();
          $('#result_2').hide();
          $.get(\"func.php\", {
            func: \"drop_2\",
            drop_var: $('#drop_2').val()
          }, function(response){
            $('#result_2').fadeOut();
            setTimeout(\"finishAjax_tier_three('result_2', '\"+escape(response)+\"')\", 400);
          });
            return false;
        });
    </script>"
    ;
    }


    //**************************************
    //     Second selection results     //
    //**************************************
    if($_GET['func'] == "drop_2" && isset($_GET['func'])) { 
       
    drop_2($_GET['drop_var']); 
    }

    function 
    drop_2($drop_var)
    {  
        include_once(
    'db.php');
        
    $result mysql_query("SELECT * FROM three_drops WHERE tier_two='$drop_var'"
        or die(
    mysql_error());
        
        echo 
    '<select name="drop_3" id="drop_3">
              <option value=" " disabled="disabled" selected="selected">Choose one</option>'
    ;

               while(
    $drop_3 mysql_fetch_array$result )) 
                {
                  echo 
    '<option value="'.$drop_3['tier_three'].'">'.$drop_3['tier_three'].'</option>';
                }
        
        echo 
    '</select> ';
        echo 
    '<input type="submit" name="submit" value="Submit" />';
    }
    ?>
    Last edited by cpradio; Feb 4, 2013 at 10:03. Reason: Added php tags

  2. #2
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    78
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Before you try to test the $_GET associative array data, check that it even exists first.

    PHP Code:
    if(isset($_GET['func']) && $_GET['func'] == "drop_1") { 
    drop_1($_GET['drop_var']); 

    You're doing the same thing around line 61 as well, hence why you're getting two of the same error at different locations.

  3. #3
    SitePoint Member
    Join Date
    Aug 2012
    Location
    Reading, England, United Kingdom
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi
    Thanks a lot its working now.

  4. #4
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what you did to solve the issue..?

  5. #5
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,127
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by IT Freak View Post
    what you did to solve the issue..?
    If you read post #2 you will see he was asked to add isset() check before using the $_GET value he expected to be there. This way if the value didn't exist, the notice goes away because he won't try and use it.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •