autocomplete not working on one page but working perfectly on another

autocomplete not working on one page but working perfectly on another

Both pages have the same header info since they both use include to echo the header with the required jquery and jquery ui references.

  1. include("includes/header.php");

    if ( !$_SESSION['logged'] ) {
    header ("Location: index.php");
    }

    $db = db_connect();







  2. echo '
    <script type="text/javascript">
    $(document).ready(function(){
       
        $("input#provider").autocomplete(function(){
        source: [';

        $providerlist = mysql_query("SELECT * FROM users");
        while ( $provider = mysql_fetch_array($providerlist) ) {
        echo '"' . $provider['username'] . '", ';
        }
        echo ']
        });

    });
    </script>';














  3. echo '<form name="newencounter" method="POST" action="encounters.php?mode=new&pid=' . $_GET['pid'] . '">
  4. <input type="text" name="provider" id="provider" />
  5. </form>';