Home How to echo <img src with PHP variables as values of the src attribute
Reply: 0

How to echo <img src with PHP variables as values of the src attribute

user1382
1#
user1382 Published in April 27, 2018, 6:43 am

This question already has an answer here:

  • PHP parse/syntax errors; and how to solve them? 13 answers

I am getting error when I try to echo image in PHP. Here is my code:

$sql = "SELECT id, title, filename FROM images";
$result = $conn->query($sql);


if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    $pathx = "directory/images/";

    echo '
    <img src = "'$pathx'.'$row["filename"]'">
    ';
    //filenames in database end with appropriate image extensions like .png

}

And I am getting this error: Parse error: syntax error, unexpected '$pathx' (T_VARIABLE), expecting ',' or ';' in C:\xampp\htdocs\display.php on line 29

I have checked solutions from similar questions from here on Stackoverflow and implemented some of the accepted answers still my problem is not solved.

meanwhile something like the code below works well. So why is the one above not working?

echo'<img src = "directory/images/girl-g2109_5_720.jpg">';
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.322071 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO