Using PHP, MSSQL, Jquery for instant search

I am trying to implement an instant search function using PHP, jQuery, and a MS SQL database. I’m not sure what the issue I’m having is, to be honest. I’m not getting any php errors, and the only thing I could possibly think it is is that there is some confusion in connection to the database. I have the files on Windows Server 2003, and I’m attempting to access an MSSQL database on another server running Windows Server 2008. I’m completely new to these servers and to programming across them like this. (I’m an IT intern.) Here is the code I am using, it was modified from a tutorial for creating an instant search. This is the code I have at this point.

The PHP file:

  • Amazon RDS - are there workarounds to change a database time zone in SQL Server?
  • Function vs. Stored Procedure in SQL Server
  • Update Geography column in table
  • Find number of concurrent users in a SQL records
  • Is Contains Equivalent To Like In SQL Server
  • Convert UTC Milliseconds to DATETIME in SQL server
  • <?php
    if(!empty($_GET['q'])) {
    function search() {
    $server = 'Windows2008ServersName';
    $con = mssql_connect($server, 'username', 'password')
        or die("Couldn't connect to SQL Server on $server");
    mssql_select_db('dbname', $con);
    $q = str_replace("'","''",$_GET['q']);
    $sql = mssql_query("
            db.First_Name, SUBSTR(db.Last_Name,1,300)
        FROM db
        WHERE db.First_Name LIKE '%{$q}%' OR db.Last_Name LIKE '%{$q}%'
    or die ( 'Query Error' );
    //Create an array with the results
    while($v = mssql_fetch_object($sql)){
        $results[] = array(
    //using JSON to encode the array
    echo json_encode($results);

    The Javascript file:

    var runningRequest = false;
    var request;
    //Identify the typing action
        var $q = $(this); //get the letter
        //if it's not a search term return false
        if($q.val() == ''){
            return false;
        //Abort opened requests to speed it up
        request = $.getJSON('search.php',{
    //Create HTML structure for the results and insert it on the result div
    function showResults(data, highlight){
           var resultHtml = '';
            $.each(data, function(i,item){
                resultHtml+='<div class="result">';
                resultHtml+='<h2><a href="#">'+item.title+'</a></h2>';
                resultHtml+='<p>', '<span     class="highlight">'+highlight+'</span>')+'</p>';
                resultHtml+='<a href="#" class="readMore">Read more..</a>'

    The HTML file:

        <title>Instant Search</title>
        <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="js/search.js"></script>
    <style> /*css*/  </style>
        <form method="get" action="">
            <input type="text" id="q" name="q" />
        <input type="submit" value="Search" />
       <div id="results"></div>

    PHP is installed on the web server, but I’m not sure that it’s installed on the MSSQL server, could this be the issue? I’m not really familiar with how the servers need to be set up to work with one another. Especially in a situation like this.

    One Solution collect form web for “Using PHP, MSSQL, Jquery for instant search”

    Don’t think you want the ‘$’ on the q var in the javascript; it could be allowed (I don’t think it is, but I haven’t tried it), but it’s not necessary and it is confusing.

    There may be more but this leaped out at me as bad.

    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.