Jump to content

Trying to use AJAX/jQuery, but getting a very odd error


ShootingBlanks

Recommended Posts

Hello - I tried posting this on jQuery's official forum, but for some reason it's not letting me make any posts.  I'm really hoping someone on here can help, because this is making me nutty!

 

Basically I just want to have a drop-down menu where when someone selects something then a second drop-down menu appears with a new set of options (the options are different depending on what was selected in the first drop-down menu).  Then when the user selects something from the second drop-down menu, a third one appears that is populated with options based on what was selected in the second drop-down menu.  This continues on like this until a final selection is reached.

 

The info from the drop-down menus is populated through MySQL relational database tables.

 

Here's where it gets weird.  I have the first menu working.  When you select something from the second menu, instead of the third menu appearing, I just get this error:

 

Fatal error: Call to undefined function mysql_get_last_message() in C:\htdocs\jQuery\configurator\draw_third_select.php on line 15

 

The reason this is weird is because the code for the second menu appearing (which works) is almost identical to the third one appearing (minus some few obvious variable name changes).  Here is code and details on everything I've done so far:

 

configurator.php - (main page):

 

<?php require_once('Connections/connection.php'); ?>
<?php
/********************************************************************************************/

// *** Get a list of level1 items in the database to populate the first drop-down menu with
mysql_select_db($database_db, $db);
$query_level1 = "SELECT *
			 FROM level1
			 ORDER BY value";

// *** Execute select statement to retrieve categories ***
$level1 = mysql_query($query_level1, $db) or die(mssql_get_last_message());
// *** Fetch row ***
$row_level1 = mysql_fetch_assoc($level1);

/********************************************************************************************/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-min.js"></script>
<script type="text/javascript">
// *** First drop-down menu functionality *** //
$(document).ready(function () {
$("#First_SelectID").change(function() {
	if ($("#First_SelectID").val() != "0") {
		$('#Second_SelectID').show();
		$.ajax({
			type: "POST",
			url: "draw_second_select.php",
			data: "first_value=" + $('#First_SelectID').val(),
			success: function(msg){
				$('#Second_SelectID').html(msg);
			} // end success
		}) // end ajax
	} else {
		$('#Second_SelectID').hide();
	} // end if
});  // end change function
});

// *** Second drop-down menu functionality *** //
$(document).ready(function () {
$("#Second_SelectID").change(function() {
	if ($("#Second_SelectID").val() != "0") {
		$('#Third_SelectID').show();
		$.ajax({
			type: "POST",
			url: "draw_third_select.php",
			data: "second_value=" + $('#Second_SelectID').val(),
			success: function(msg){
				$('#Third_SelectID').html(msg);
			} // end success
		}) // end ajax
	} else {
		$('#Third_SelectID').hide();
	} // end if
});  // end change function
});
</script>
<title>Test configurator</title>
</head>

<body>
<select name="First_Select" id="First_SelectID">
<option value="0">--SELECT AN OPTION--</option>
<?php
do { ?>
	<option value="<?php echo $row_level1['id1']?>"><?php echo $row_level1['value']?></option>
<?php
} while ($row_level1 = mysql_fetch_assoc($level1));
	mysql_data_seek($level1, 0);
	$row_level1 = mysql_fetch_assoc($level1);
?>
</select>

<div id="Second_SelectID"></div>

<div id="Third_SelectID"></div>
</body>
</html>

 

draw_second_select.php - (shows second drop-down menu):

 

<?php require_once('Connections/connection.php'); ?>
<?php
/********************************************************************************************/

$val1 = $_POST['first_value'];

// *** Get a list of level2 items in the database to populate the first drop-down menu with
mysql_select_db($database_db, $db);
$query_level2 = "SELECT *
			 FROM level2
			 WHERE id1 = " . $val1 . "
			 ORDER BY value";

// *** Execute select statement to retrieve categories ***
$level2 = mysql_query($query_level2, $db) or die(mysql_get_last_message());
// *** Fetch row ***
$row_level2 = mysql_fetch_assoc($level2);

/********************************************************************************************/

$html = '<br /><select name="Second_Select">' . "\n";
$html .= '<option value="0">--SELECT AN OPTION--</option>';
do {
$html .= '<option value="' . $row_level2['id2']. '">' . $row_level2['value']. '</option>';
} while ($row_level2 = mysql_fetch_assoc($level2));
mysql_data_seek($level2, 0);
$row_level2 = mysql_fetch_assoc($level2);
$html .= '</select>' . "\n";
echo $html;
exit();
?>

 

draw_third_select.php - (SHOULD show third drop-down menu):

 

<?php require_once('Connections/connection.php'); ?>
<?php
/********************************************************************************************/

$val2 = $_POST['second_value'];

// *** Get a list of level3 items in the database to populate the second drop-down menu with
mysql_select_db($database_db, $db);
$query_level3 = "SELECT *
			 FROM level3
			 WHERE id2 = " . $val2 . "
			 ORDER BY value";

// *** Execute select statement to retrieve categories ***
$level3 = mysql_query($query_level3, $db) or die(mysql_get_last_message());
// *** Fetch row ***
$row_level3 = mysql_fetch_assoc($level3);

// $totalRows_level3 = mysql_num_rows($level3);

/********************************************************************************************/

$html = '<br /><select name="Third_Select">' . "\n";
$html .= '<option value="0">--SELECT AN OPTION--</option>';
do {
$html .= '<option value="' . $row_level3['id3']. '">' . $row_level3['value']. '</option>';
} while ($row_level3 = mysql_fetch_assoc($level3));
mysql_data_seek($level3, 0);
$row_level3 = mysql_fetch_assoc($level3);
$html .= '</select>' . "\n";
echo $html;
exit();
?>

 

Conncetions/connection.php - (connection script):

 

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_db = "localhost";
$database_db = "configurator";
$username_db = "my_database_username";
$password_db = "my_database_password";

$db = mysql_pconnect($hostname_db, $username_db, $password_db) or trigger_error(mysql_error(),E_USER_ERROR); 
$conn = new mysqli($hostname_db, $username_db, $password_db, 'configurator') or die('Cannot open database');
?>

 

Table "level1" - structure:

level1_structure.jpg

 

Table "level1" - content:

level1_content.jpg

 

Table "level2" - structure:

level2_structure.jpg

 

Table "level2" - content:

level2_content.jpg

 

Table "level3" - structure:

level3_structure.jpg

 

Table "level3" - content:

level3_content.jpg

 

Thanks so much in advance for any help that anyone can offer.  Sorry for the long post, but I just wanted to be detailed.  This is causing me so much confusion!!!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.