Uploading cities of the input?

Hello!
There are 2 input
Country and city
When you enter the country, when you start to enter in инпут2 city loaded city of this country
The trouble is that the country loads correctly and the city is constantly empty
It was written long ago, used to work but now no

JS
//loading the list of countries
 $('.country-load').autocomplete("autocomplete.php", {
delay:400,
minChars:2,
matchSubset:0,
autoFill:true,
matchContains:1,
cacheLength:1,
selectFirst:true,
 extraParams: {type:1},
 maxItemsToShow:10, 
onItemSelect:selectItem
});

 //loading of list of cities
 $('.city-load').autocomplete("autocomplete.php", {
delay:400,
minChars:2,
matchSubset:0,
autoFill:true,
matchContains:1,
cacheLength:1,
selectFirst:true,
 extraParams: {type:2,country:0},
maxItemsToShow:10,
 width: 180
});

 function selectItem(li, input) { 
 if( li == null ) var sValue = "Nothing selected!";
 if( !!li.extra ) var sValue = li.extra[0];
 else var sValue = li.selectValue;
 $(input).attr('data', sValue);
 }


PHP
<?php



$dbhost = 'localhost';
$dbuser = ";
$dbpass = ";
$dbname = ";

function isAjax()
{
 return ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) ? true:false;
}
if ( isAjax() ) {
 $mysql = mysql_connect( $dbhost, $dbuser, $dbpass );
 if ( $mysql ) {
 $db = mysql_select_db( $dbname, $mysql );
 if ( $db ) {
 @mysql_query( "SET NAMES utf8", $mysql );
 $query = mysql_real_escape_string( $_GET['q'], $mysql );
 $type = abs( intval( $_GET['type'] ) );
 if ( $type == 1 ) {
 $select = mysql_query( "SELECT * FROM country WHERE LOWER(name) LIKE '{$query}%'", $mysql );
 if ( mysql_num_rows( $select ) > 0 ) {
 while ( $assoc = mysql_fetch_assoc( $select ) ) {
 $data[] = $assoc['name'].'|'.$assoc['country_id'];
}
 mysql_close( $mysql );
 echo implode( "\n", $data );
}
}
 if ( $type == 2 ) {
 $country = abs( intval( $_GET['country'] ) );
 $select = mysql_query( "SELECT * FROM city WHERE country_id='{$country}' AND LOWER(name) LIKE '{$query}%'", $mysql );
 if ( mysql_num_rows( $select ) > 0 ) {
 while ( $assoc = mysql_fetch_assoc( $select ) ) {
 $data[] = $assoc['name'];
}
 mysql_close( $mysql );
 echo implode( "\n", $data );
}
}
}
}
}
?>
March 19th 20 at 08:49
0 answer

Find more questions by tags JavaScriptPHP