Notice: Undefined index error

Discussion in 'PHP' started by batoo, Apr 4, 2010.

  1. #1
    What is wrong here?

    
    $actual_id = ($_GET['category_id']);  // line 1 , here is the error, but what? :)
    
    if($actual_id){
    	$finded = false;
    	
    	for($a = 0; $a < count($first_level) && !$finded; $a++){
    		if($first_level[$a]["id"] == $actual_id) $finded = true;
    	}
    	
    	if(!$finded){
    		for($b = 0; $b < count($second_level) && !$finded; $b++){
    			if($second_level[$b]["id"] == $actual_id){
    				$finded = true;
    				$actual_id = $second_level[$b]["parent"];
    			}
    		}		
    	}
    	
    	if(!$finded) $actual_id = $first_level[0]["id"];
    }else{
    	$actual_id = $first_level[0]["id"];
    }
    PHP:
     
    batoo, Apr 4, 2010 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    I think your PHP configuration is set so that even E_NOTICE errors are shown,

    I suggest you use this code
    $actual_id = (isset($_GET['category_id']) && $_GET['category_id']);
    PHP:
    instead of
    $actual_id = ($_GET['category_id']);
    PHP:
    FYI:
    * You need to do something similar with the line {{{ $actual_id = $first_level[0]["id"]; }}}
    * showing E_NOTICE is a good practice when on a development environment
     
    nabil_kadimi, Apr 4, 2010 IP
  3. batoo

    batoo Greenhorn

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    Thanks a lot man, it works.

    BOW!
     
    batoo, Apr 4, 2010 IP