jQuery autocomplete: undefined index term (2)
http://www.warriorforum.com/programm...ndex-term.html
But, I tried hard to post their and was unsuccessful, and I have already discussed the reason of this problem here: http://www.warriorforum.com/suggesti...g-replies.html
But I didn't get any positive response. That's why I am posting in a new thread now.
OK. I have solved the problem of Undefinex index that I mentioned in the last post by adding the condition "if ( !isset($_REQUEST['term']) )
" but now there is another problem. It doesn't show me the suggestions. Whenever I enter 2 digits of zip code, the scrip shows me the message "No search results." However, the data exists in database. Below is the screenshot of the SAMPLE database table that I have created for this test work.

And here is the link where I am testing this script where you can see that it doesn't work.
Suggest Zip
And here is the code of full page.
<html>
<head>
<title>Suggest Zip</title>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
jQuery(document).ready(function($){
$('#zipsearch').autocomplete({source:'suggest_zip.php', minLength:2});
});
</script>
</head>
<body>
<form action="" method="post">
Enter your zipcode:
<input type="text" id="zipsearch" />
<br />
<input type="submit" value="Search" />
</form>
<?php
// if the 'term' variable is not sent with the request, exit
if ( !isset($_REQUEST['term']) )
exit;
// connect to the database server and select the appropriate database for use
$dblink = mysqli_connect('mysql5.000webhost.com', 'a8995753_db2 ', 'xxxxxxxxx', 'a8995753_db2') or die("Error: " . mysqli_connect_error() );
// query the database table for zip codes that match 'term'
$rs = mysqli_query($dblink, 'select zipCode, city, state from zipcode where zipCode like "'. mysqli_real_escape_string($dblink, $_REQUEST['term']) .'%" order by zipCode asc limit 0,10') or die( "Error: " . mysqli_error($dblink) );
// loop through each zipcode returned and format the response for jQuery
$data = array();
if ( $rs && mysqli_num_rows($rs) )
{
while( $row = mysqli_fetch_array($rs, MYSQL_ASSOC) )
{
$data[] = array(
'label' => $row['zipCode'] .', '. $row['city'] .' '. $row['state'] ,
'value' => $row['zipCode']
);
}
}
// jQuery wants JSON data
echo json_encode($data);
flush();
?>
</body>
</html> -
Brandon Tanner -
Thanks - 1 reply
Signature{{ DiscussionBoard.errors[8211572].message }}-
freetutorial -
Thanks - 1 reply
{{ DiscussionBoard.errors[8260746].message }}-
phpg -
Thanks
{{ DiscussionBoard.errors[8261502].message }} -
-
-