Link to home
Start Free TrialLog in
Avatar of rcowen00
rcowen00Flag for United States of America

asked on

Notice: Undefined index: func in .........include/forms/func.php on line 21

Hi Experts,

I am trying to re-create chained select boxes using Ajax from http://www.blueicestudios.com/chained-select-boxes-using-php-mysql-ajax/, but I am getting the following error.  It is probably something very simple, but I can't seem to locate the problem.  Any suggestions?

Notice: Undefined index: func in ......include/forms/func.php on line 21

reviewMarkup.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN http: //www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('#wait_1').hide();
	$('#drop_1').change(function(){
	  $('#wait_1').show();
	  $('#result_1').hide();
      $.get("func.php", {
		func: "drop_1",
		drop_var: $('#drop_1').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
    	return false;
	});
});

function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>

</head>
<body>
    <form action="" method="post">

    <?php
    error_reporting(E_ALL);
    include "include/userConnect.php";
    include "func.php";
    if (array_key_exists('loanAuditKey', $_POST)) {
          $loanAuditKey = $_POST['loanAuditKey'];
          } else {
          $loanAuditKey = $_GET['loanAuditKey'];
          }
        ?>
    <div align="center">
        </br>
          </br>  
   <select id="drop_1" name="drop_1" class="select">
                    <option value="" selected="selected" disabled="disabled">Select a Category</option>
      
      <?php getTierOne(); ?>
               </select>
    
    
    <span id="wait_1" style="display: none;">
    <img alt="Please Wait" src="../../images/ajax-loader.gif"/>
    </span>
    <span id="result_1" style="display: none;"></span> 
<?php if(isset($_POST['submit'])){
	$drop = $_POST['drop_1'];
	$tier_two = $_POST['tier_two'];
	echo "You selected ";
	echo $drop." & ".$tier_two;
}

?>
</form> 
</body> 
</html>

Open in new window


func.php
<?php
//**************************************
//     Page load dropdown results     //
//**************************************
function getTierOne()
{
	$result = mysql_query("SELECT DISTINCT findingCategoryKey, findingCategoryName FROM findingCategory WHERE active=1") 
	or die(mysql_error());

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

}

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

function drop_1($drop_var)
{  
    include "include/userConnect.php";
	$result = mysql_query("SELECT findingKey, description, findingVerbiage FROM finding WHERE findingCategoryKey='$drop_var'AND active=1") 
	or die(mysql_error());
	
	echo '<select name="tier_two" id="tier_two">
	      <option value=" " disabled="disabled" selected="selected">Choose one</option>';

		   while($drop_2 = mysql_fetch_array( $result )) 
			{
			  echo '<option value="'.$drop_2['findingKey'].'">'.$drop_2['description'].'</option>';
			}
	
	echo '</select> ';
    echo '<input type="submit" name="submit" value="Submit" />';
}
?>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

This is a Notice, not an Error.  You may be able to suppress the message by adding the @ to the function call.  Start the exploration here:
http://php.net/manual/en/function.error-reporting.php
Avatar of rcowen00

ASKER

I guess I then have a slightly different question, the process works until I select the first drop-down, then the image is view-able in func.php line 54, then nothing.  I am very inexperienced with Ajax, how do I go about trouble shooting it?  thanks!
Avatar of Jagadishwor Dulal
Can you post your table structure? I think you have problem in your select query, it seems there is no problem.... If I have created right fields.

SELECT findingKey, description, findingVerbiage FROM finding WHERE findingCategoryKey='$drop_var' AND active=1

Open in new window


Again Ray already write above your problem it's the problem by
 error_reporting(E_ALL);

Open in new window

comment this line and test.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Change the order of line 21. Currently you're checking a value and then checking if it's set! You should check if it's set and the check the value...

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

Open in new window

This way, if it's not set, it won't check the value, and therefore won't give you the NOTICE!
Here is the table structure
User generated image
I also commented out error_reporting(E_ALL); with no change except the notice doesn't show.

I am reviewing the links from Ray now.
To prevent the NOTICE and fix your problem, read my previous post - I've already given you the answer.

DO NOT remove the error reporting directive while degugging - hiding error mressages is not a valid way of fixing your code ;)