title: Retrieving BLOB image from database using autocomplete selection
body: <p>I'm trying to display a blob image stored in a database, I'm not getting any errors but the image isn't displaying, I'm just getting the default &quot;no image&quot; icon. Here's my code:</p>
  <pre><code>&lt;script&gt;
    function showEmpimg(str) {
      var xhttp;
      if (str == &quot;&quot;) {
        document.getElementById(&quot;user-id&quot;).innerHTML = &quot;&quot;;
        return;
      }
      xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 &amp;&amp; this.status == 200) {
        document.getElementById(&quot;face&quot;).innerHTML = this.responseText;
        }
      };
      xhttp.open(&quot;POST&quot;, &quot;getimage.php?q=&quot;+str, true);
      xhttp.send();
    }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id=&quot;face&quot; class=&quot;face&quot;&gt; 
    &lt;/div&gt;
    &lt;input type=&quot;text&quot; class=&quot;form-control&quot; id=&quot;user-id&quot; placeholder=&quot;ID&quot; name=&quot;emp_id&quot; onchange=&quot;showEmpimg(this.value)&quot; required maxlength=&quot;6&quot; /&gt;
  </code></pre>
  <p>And the php file:</p>
  <pre><code>&lt;?php
  
  $db = mysqli_connect(&quot;localhost&quot;,&quot;root&quot;,&quot;test1&quot;,&quot;dar&quot;);
  $sql = &quot;SELECT emp_img FROM employees WHERE emp_id LIKE 'q'&quot;;
  $sth = $db-&gt;query($sql);
  $result=mysqli_fetch_array($sth);
  echo '&lt;img src=&quot;data:image/jpeg;base64,'.base64_encode( $result['emp_img'] ).'&quot;/&gt;';
  
  ?&gt;
  </code></pre>
  <p>Any ideas?</p>