2

I know this question has been asked many times but I couldnot solve this using any of them. I am new to sqlite and cannot understand what I am doing wrong.

WHAT I AM TRYING

I am trying to make a profile view page. I am able to fetch all details from my sqlite database but i am not able to display my profile picture.

TABLE STRUCTURE

    **username|landline|mobile|email|profilepicture**

         john |xxxxxxxx|xxxxxx|[email protected]|blob

WHAT I TRIED

  $sql = "SELECT * FROM profile";
  $query = $db->query($sql);
  while($row = $query->fetchArray(SQLITE3_ASSOC) ){
  echo "NAME = ". $row['user_name'] . "<br/>";
  echo "LANDLINE = ". $row['user_landline'] ."<br/>";
  echo "MOBILE = ". $row['user_mobile'] ."<br/>";
  echo "EMAIL =  ".$row['user_email'] ."<br/>";
  header('Content-Type: image/png');
  echo $row['user_profile_picture'];
  }


  <html>
  <img src='profile.php?imgid=<?php echo $row['user_profile_picture'];?>'/>
  </html>

But the image dosenot show and also the rest of the data dosenot display when i putheader('Content-Type: image/png');

1 Answer 1

2

Create an image.php:

<?php 
$sql = "SELECT user_profile_picture FROM profile WHERE id = " . $_GET['id'];
$query = $db->query($sql);
$row = $query->fetchArray(SQLITE3_ASSOC);

header('Content-Type: image/png');
echo $row['user_profile_picture'];

In profile.php:

<img src='image.php?id=<?php echo $row['id'];?>'/>
Sign up to request clarification or add additional context in comments.

4 Comments

<img src='image.php?id=<?php echo $row['id'];?>'/> what does this mean. mainly what is id
I assume you have an id column (a primary key) in your table.
is this only support if image is png?
Nope, you can also store the image type in the db during upload.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.