0

I've done some research and followed a tutorial exactly, with minor changes, but I can't seem to get this to work. No dropdown appears. Can you look at the code and tell me what is not happening?

<div class="ui-widget">
    <label for="skills">Skills: </label>
    <input id="skills">
</div>
<script>
$(function() {
    $( "#skills" ).autocomplete({
         width:448,
         delimiter: /(,|;)\s*/,
         lookup: <?php echo "'autocomplete(#skills)'" ?>
    });
});
</script>

<?php     
$servername = 'localhost';
$username = 'xx';
$password = 'xx';

$con = mysql_connect($servername,$username,$password);
mysql_select_db('c9', $con);

function autocomplete($inputName){
    $searchTerm = $_GET[$inputName];
    $query = mysql_query("SELECT * FROM clients WHERE fname LIKE '%".$searchTerm."%' ORDER BY fname ASC");
    while ($row = mysql_fetch_array(MYSQL_ASSOC)) {
        $data[] = $row['fname'];
    }
    //return json data
    echo json_encode($data);
}

?>
fungusanthrax
  • 192
  • 2
  • 13
  • 1
    It looks like you're getting confused about what runs where. PHP runs on the server, JS on the client. JS can't directly call PHP functions which is what it looks like you're trying to do with ``? – Jonnix Oct 25 '16 at 13:51
  • No, I think that's okay. But that it needs to be out of the string. Notice it's a json string he seems to be trying to pass to the autocomplete method in the javascript (looking at the php function), but both his delimiter and lookup are not in quotes (quotes are in the echo and not around the php echo) – Anees Saban Oct 25 '16 at 13:52
  • `mysql_*` functions are deprecated since PHP 5.5 (and **removed entirely** in PHP 7) and you should [stop using them](http://stackoverflow.com/q/12859942) if you can. You should choose another API that allows you to use [prepared statements](http://stackoverflow.com/q/60174/) (which you *really should* when dealing with variables), like `mysqli_*` or PDO - see [choosing an API](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Qirel Oct 25 '16 at 14:02
  • @Novice yes, I excluded that code, but I'm sure it is correct – fungusanthrax Oct 25 '16 at 22:13
  • i don't know how to use `lookup` option never used that , what does it do? i ask because we normally use `source` like `source:result.php` – Vinay Oct 26 '16 at 15:21

0 Answers0