?
Solved

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

Posted on 2013-06-23
7
Medium Priority
?
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 111

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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 43

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 43

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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

752 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