-2

Receiving the following:

Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 23 Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 67 Notice: Undefined index: func in /Applications/XAMPP/xamppfiles/htdocs/select2/func.php on line 114

Here are the offending lines:

Line 23

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

function drop_1($drop_var)
{  

Line 67

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

function drop_2($drop_var)
{ 

Line 114

if($_GET['func'] == "drop_3" && isset($_GET['func'])) { 
drop_3($_GET['drop_var']); 
}

function drop_3($drop_var)
{  

I looked in the existing questions and didn't find an answer where an if statement was attached with the operator &&.

Thanks,

user3019140
  • 9
  • 1
  • 6

2 Answers2

2

Change the order of your condition to this:

if(isset($_GET['func']) && $_GET['func'] == "drop_1" )

Now you are checking if the 'func' index is set first before using it.

Ibu
  • 42,752
  • 13
  • 76
  • 103
1

You have the order of your logical operators backwards. First you need to check to see if the variable is set and then you need to check it's value. If the first check is false then the second one will never happen due to short circuiting which prevents the error message you see.

if($_GET['func'] == "drop_1" && isset($_GET['func'])) { 

should be:

if(isset($_GET['func']) && $_GET['func'] == "drop_1") { 
John Conde
  • 217,595
  • 99
  • 455
  • 496