Search code examples
phpmysqlbase-url

Displaying photos from url stored in database


This is my database: enter image description here

I'm trying to display the image like this

  <?php
$displaymyavatar="SELECT * FROM avatars INNER JOIN users ON avatars.users_id=users.id WHERE username='$login_session'";
 $result_set=mysqli_query($db,$displaymyavatar);
 while($row=mysqli_fetch_array($result_set)){?>
              <img class="avatar" src='<?=$_SERVER['HTTP_REFERER'] . $row['image_file'];?>' alt="">
 <?php };?>

I thought I found a solution here but the image is not displaying. The image is uploaded in the folder "uploads"


Solution

  • This works:

         <?php
    $displaymyavatar="SELECT * FROM avatars INNER JOIN users ON avatars.users_id=users.id WHERE username='marydoe'";
     $result_set=mysqli_query($db,$displaymyavatar);
     while($row=mysqli_fetch_array($result_set)){?>
                  <img class="avatar" src="core/<?php echo $row['image_file'] ?>" />
     <?php };?>