Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP Display Image (URL from Database)

New Here ,
Nov 17, 2010 Nov 17, 2010

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

TOPICS
Server side applications
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Nov 17, 2010 Nov 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_que
...
Translate
Guest
Nov 17, 2010 Nov 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" />

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 17, 2010 Nov 17, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines