title: Displaying Search Results in the same page in PHP & MySQL using AJAX
body: <p>I'm trying to make Search using PHP and MySQL. I'm using a basic form technique for submitting the data. </p>
  
  <pre><code>&lt;form action="search.php" method="get"&gt;
      &lt;div class="form-field"&gt;
        &lt;label for="search-field"&gt;Search&lt;/label&gt;
        &lt;input type="search" name="s" placeholder="Enter your search term..." results="5"&gt;
        &lt;input type="submit" value="Search"&gt;
      &lt;/div&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>Then, I'm passing it through a function inside 'search.php'. Then for the algorithm, it's a simple MySQL statement. </p>
  
  <pre><code>$query =("
    SELECT *
    FROM details
    WHERE (`subjects` LIKE '%".$term."%')
    OR (`name` LIKE '%".$term."%')
  ");
  </code></pre>
  
  <p>However, I wish to display the contents in the same page without any form . I'd like to implement JQuery/an AJAX Method. 
  My Function is implemented in a class, and it is: </p>
  
  <pre><code>public function search($search_term) {
  
  $term = $this-&gt;mysqli-&gt;real_escape_string($search_term);
  $query =("
    SELECT *
    FROM details
    WHERE (`subjects` LIKE '%".$term."%')
    OR (`name` LIKE '%".$term."%')
  ");
  $r=  $this-&gt;mysqli-&gt;query($query);
  if (!$r) {
      echo"&lt;br/&gt;";
  die('Invalid query');}
  </code></pre>
  
  <p>I can provide more of my code if my question is lackluster. </p>