• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Displaying images in php from database

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I got the path of images stored in my database with a blob. I wanna access them in php and display them aswell. However, instead of displaying the picture, it displays the select command.



I just tried these 2 little lines as a test, if the display of the image even works. It does not sadly.

 
Sheriff
Posts: 22082
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthias Utrata wrote:Hello. I got the path of images stored in my database with a blob. I wanna access them in php and display them aswell. However, instead of displaying the picture, it displays the select command.


Sure, because that's what's your code is doing - it creates a string variable with the SQL command, and then it echoes that string variable. There is no code to actually execute the command. I suggest you read about PDO, then try to change your code. To help you, here's a few steps that you need to take:

* Execute the command.
* From the result, get the path. You still shouldn't echo the path because that too is a string.
* Retrieve the file from disk and display its contents.


Edit: here's a PDO guide that's apparently a bit easier to use: https://phpdelusions.net/pdo
 
Matthias Utrata
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I tried that now. It does not echo anything though.
 
Rob Spoor
Sheriff
Posts: 22082
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthias Utrata wrote:


What's the value of $row['BildID'] before you execute the query? Because if you're not seeing anything, maybe your query simply yields zero results.
 
Matthias Utrata
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can post a link of my database, if that helps

https://pastebin.com/qAxv74nV
 
Rob Spoor
Sheriff
Posts: 22082
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think that's necessary.

Can you add the following before the code you provided last time, and show us what the outcome is?
 
Matthias Utrata
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\UTR\quiz\fragen.php on line 65



That is my outcome
 
Rob Spoor
Sheriff
Posts: 22082
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I forgot that PHP tries to expand variables in double-quoted strings. Try the following instead:


But I think I already know the issue. By default, bindParam uses a string type. Try explicitly using an int type:
 
Matthias Utrata
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Notice: Trying to access array offset on value of type bool in C:\xampp\htdocs\UTR\quiz\fragen.php on line 77
$row['BildID']:

That is the error message for the first piece of code.

The second piece of code displayed nothing.
 
Rob Spoor
Sheriff
Posts: 22082
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So $row is not an array, and it does not have an index called BildId. So when you pass it to PDO, it gets turned into something that does not exist in the database. Try hard-coding the value first (BildId 1 should be valid based on your inserts):

Get this working first. Then focus on getting the BildId from somewhere else. Hint: it's not from $row.
 
Matthias Utrata
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the issue. It is something completely different, but I found it. The error was in my database
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic