javascript - Live search with AJAX -


i need build live search don't know ajax , javascript, understand html, css , php.can tell me i'm doing wrong?

<script>     function livesearch(str) {         if (str == "") {             document.getelementbyid("txthint").innerhtml = "";             return;         }         else {              if (window.xmlhttprequest) {                 // code ie7+, firefox, chrome, opera, safari                 xmlhttp = new xmlhttprequest();             }             else {                 // code ie6, ie5                 xmlhttp = new activexobject("microsoft.xmlhttp");             }              xmlhttp.onreadystatechange = function() {                 if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {                     document.getelementbyid("txthint").innerhtml = xmlhttp.responsetext;                 }             }              xmlhttp.open("get", "getuser.php?q=" + str, true);             xmlhttp.send();         }     } </script>  <input type="text" onkeypress="livesearch(this.name)" name="searchword"/>  <?php     $dbhost = 'localhost';     $dbuser = 'root';     $dbpass = '';     $dbname = 'ezcart';     $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);      if ($conn->connect_error) {         die('could not connect database: ' . $conn->connect_error);     }      $word = $_get['q'];     $sql= "select prodnam product prodnam '$q' order prodnam asc";     $result = $conn->query($sql);      if ($result->num_rows > 0) {         while($row = $result->fetch_assoc()) {             echo "<div><p>".$row[prodnam]."</p></div>";         }     }     $conn->close(); ?> 

change query

$word = $_get['q'];  $sql= "select prodnam product prodnam '%".$word."%'"; 

for more information:http://www.w3schools.com/sql/sql_like.asp


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -