Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-06-23
7
Medium Priority
?
285 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 44

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 44

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
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.
Suggested Courses

604 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