Solved

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

Posted on 2013-06-23
7
274 Views
Last Modified: 2013-08-02
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

0
Comment
Question by:rcowen00
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39270196
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
0
 

Author Comment

by:rcowen00
ID: 39270203
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!
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39270283
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.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39270998
This article shows the basics of a jQuery AJAX call.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html

For background info, you will need to have a good understanding of HTTP protocols.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/A_11271-Understanding-Client-Server-Protocols-and-Web-Applications.html

Read those over and see if that helps you get some ideas about troubleshooting, then post back with any questions.
0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39271241
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!
0
 

Author Comment

by:rcowen00
ID: 39272569
Here is the table structure
finding table structure
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.
0
 
LVL 42

Expert Comment

by:Chris Stanyon
ID: 39272688
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 ;)
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now