title: How to echo <img src with PHP variables as values of the src attribute
body: <p>I am getting error when I try to echo image in PHP.  Here is my code:</p>
  
  <pre><code>$sql = "SELECT id, title, filename FROM images";
  $result = $conn-&gt;query($sql);
  
  
  if ($result-&gt;num_rows &gt; 0) {
  // output data of each row
  while($row = $result-&gt;fetch_assoc()) {
      $pathx = "directory/images/";
  
      echo '
      &lt;img src = "'$pathx'.'$row["filename"]'"&gt;
      ';
      //filenames in database end with appropriate image extensions like .png
  
  }
  </code></pre>
  
  <p>And I am getting this error: 
      <strong>Parse error: syntax error, unexpected '$pathx' (T_VARIABLE), expecting ',' 
      or ';' in C:\xampp\htdocs\display.php on line 29</strong></p>
  
  <p>I have checked solutions from similar questions from here on Stackoverflow and implemented some of the accepted answers still my problem is not solved.</p>
  
  <p>meanwhile something like the code below works well. So why is the one above not working?</p>
  
  <pre><code>echo'&lt;img src = "directory/images/girl-g2109_5_720.jpg"&gt;';
  </code></pre>