Script is working but I still get Notice: Undefined index

Discussion in 'PHP' started by Pizzaman1123, Dec 31, 2012.

  1. #1
    Line 21: if($_GET['func'] == "drop_1" && isset($_GET['func'])) {
    drop_1($_GET['drop_var']);
    }

    Line 61: if($_GET['func'] == "drop_2" && isset($_GET['func'])) {
    drop_2($_GET['drop_var']);
    }

    They are chained drop downs and they work but I still get notices from these lines. I attached the full func.php file too if anyone would like to view it. I'm just a beginner with php so I'm pretty clueless. Thanks!
     

    Attached Files:

    Solved! View solution.
    Pizzaman1123, Dec 31, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    The file doesn't have the HTML in it, so there's no way to tell, but there has to be an element named drop_var or func in the HTML, and there most likely isn't. $_GET[''] refers to an element name in your HTML code.
     
    Rukbat, Dec 31, 2012 IP
  3. Pizzaman1123

    Pizzaman1123 Peon

    Messages:
    219
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Rukbat here is the link to the script. Everything is posted online. Somone in the comments even says that are having a problems with the undefined index too.
    http://www.blueicestudios.com/chained-select-boxes-using-php-mysql-ajax/
     
    Pizzaman1123, Dec 31, 2012 IP
  4. #4
    Line 21:if(isset($_GET['func'])){if($_GET['func'] == "drop_1") {
    drop_1($_GET['drop_var']);
    }
    }
    Line 61:if(isset($_GET['func'])){if($_GET['func'] == "drop_2") {
    drop_2($_GET['drop_var']);
    }}


    this should work
     
    amit0535, Dec 31, 2012 IP
    Pizzaman1123 likes this.
  5. Pizzaman1123

    Pizzaman1123 Peon

    Messages:
    219
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You're the best! thank you, Amit0535!
     
    Pizzaman1123, Dec 31, 2012 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #6
    Sloppy... multiple IF statements doing the job of one.

    
    if ( isset($_GET['func']) && ($_GET['func'] == "drop_1") ) { 
    	drop_1($_GET['drop_var']); 
    }
    
    if ( isset($_GET['func']) && ($_GET['func'] == "drop_2") ) { 
    	drop_2($_GET['drop_var']); 
    }
    
    Code (markup):
    Much better. I'd also add some form of internal warning or error handling for if those values are not set.
     
    deathshadow, Jan 1, 2013 IP