jQuery UI : Autocomplete Field from Mysql

What I’m trying to solve:
User, inputs a zipcode like 08212, or any US zipcode for that matter and jquery UI Autocomplete calls this source file:


, that file does a query against the database for certain fields (described below) based on the zipcode entered.

Have a form/jquery on index.php :

Assume that all the jquery UI code is already in this file

    	<script type="text/javascript">
    				source: "../src/php/registration/getFanLoc.php",
    				maxLength: 5

    <form method="post" id="FanDetail">
      <div class="ui-widget">
         <label for="zip">Zip: </label>
         <input id="zip" name="zipcode" value="US Zipcode" onFocus="clearText(this)" /><br />

the getFanLoc.php file - that queries mysql for any records corresponding to the 5 digit zipcode entered:

    	$zip = mysql_real_escape_string($_POST['zipcode']); //////
    	require_once('../../cfg/dbi.php') or die('Cant require dbi');
    	$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
    	$sth = $dbh->prepare(
        'SELECT fanDetLocID, fanDetLocCity, fanDetLocState FROM fanDetailLocation WHERE fanDetLocZip = ?');
    	$sth->bindParam(1, $zip);
    	while ($res = $sth->fetch(PDO::FETCH_ASSOC)) {
    		$location = "<a href='#' value='$res['fanDetLocID']>".$res['fanDetLocCity'].", ".$res['fanDetLocState']."</a>";
    	echo $location;

    catch(PDOException $e){
    	file_put_contents('../../../PDODBConnectionErrors.txt', 'ERROR: [getFanLoc.php] about '.$e->getMessage().'<br>', FILE_APPEND);


I was originally having trouble, because it wasn’t connecting to the database and PDODBConnectionErrors.txt had the errors, but I’ve since


that part, and now it doesnt do anything, but now doesnt throw an error in the file either.

Anyone see what I’m doing wrong?

I’m pretty newbie working with the

autocomplete jQuery UI widget

, so go easy on me :slight_smile: