Skip to main content
Participant
November 17, 2010
Answered

PHP Display Image (URL from Database)

  • November 17, 2010
  • 2 replies
  • 2377 views

Hi, I've recnetly begun learning PHP and seem to be progressing well. However, slightly stuck. I have an image URL in my database that I want to display but it is not. What am I doing wrong? Please find my code below. Really hope someone can point out what I'm doing wrong.

<?php
include 'connectionTest.php';
$prod = "SELECT titleImg FROM pages WHERE id=1";
?>

<img src="<?php echo $prod['titleImg'];?>" alt="The Salons" width="123" height="18" />

Look forward to some help

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer

There's nothing to query your database. Also I can't tell what's in your connection include file and whether the databse is being connected. How does the source look in the browser after the page is rendered? What does the img src say when you view the source code from a browser? You need to see if the query is executed sucessfully and if it is then you need to determine the correct img path.

<?php
include ("connectionTest.php");
$prod = "SELECT titleImg FROM pages WHERE id=1";
$img_result=mysql_query($prod);
$the_image=mysql_result($img_result,0,titleImg);
?>


<img src="<?php echo $the_image ?>" alt="The Salons" />

2 replies

Correct answer
November 17, 2010

There's nothing to query your database. Also I can't tell what's in your connection include file and whether the databse is being connected. How does the source look in the browser after the page is rendered? What does the img src say when you view the source code from a browser? You need to see if the query is executed sucessfully and if it is then you need to determine the correct img path.

<?php
include ("connectionTest.php");
$prod = "SELECT titleImg FROM pages WHERE id=1";
$img_result=mysql_query($prod);
$the_image=mysql_result($img_result,0,titleImg);
?>


<img src="<?php echo $the_image ?>" alt="The Salons" />

Kriss886Author
Participant
November 17, 2010

Hi there, your solution worked. Can't quite understand what each lines does but it's working now which is the main thing. Thanks so much for your help, greatly appreciated.