title: Autocomplete using php, jquery, mysql
body: <p>I am using this source code : <a href="http://www.htmlblog.us/jquery-autocomplete" rel="nofollow">http://www.htmlblog.us/jquery-autocomplete</a> in my project but I am not able to fetch the result when I type in the autocomplete textbox.</p>
  
  <p>Where am I going wrong ?</p>
  
  <p>I use the following code</p>
  
  <p><strong>Javascript :</strong> (I use a separate file for this javascript and checked if this calls using alert and I am able to generate alert messages at runtime.)</p>
  
  <pre><code>jQuery(document).ready
   (
      function()
          {
                  $('#CourseId').autocomplete( { url:'AutoComplete_Courses.php', minLength:2 } );                
          }
   );
  </code></pre>
  
  <p><strong>Php:</strong> </p>
  
  <pre><code>&lt;?php
  
  echo('Your password must be at least 8 characters long');
  if ( !isset($_REQUEST['term']) )
      exit;
  
  $dblink = mysql_connect('localhost', 'root', '') or die( mysql_error() );
  mysql_select_db('mydatabase');
  
  $rs = mysql_query('select courseid, coursename, creditpoints from coursedetails where coursename like "'. mysql_real_escape_string($_REQUEST['term']) .'%" order by coursename asc limit 0,10', $dblink);
  
  $data = array();
  if ( $rs &amp;&amp; mysql_num_rows($rs) )
  {
      while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
      {
          $data[] = array(
              'label' =&gt; $row['courseid'] .', '. $row['coursename'] .' '. $row['creditpoints'] ,
              'value' =&gt; $row['courseid']
          );
      }
  }
  
  echo json_encode($data);
  flush();
  </code></pre>