Solved

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

Posted on 2013-06-23
7
278 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 109

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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 109

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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

815 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

8 Experts available now in Live!

Get 1:1 Help Now