Rerieve Image path from database ---- problem please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Rerieve Image path from database ---- problem please help

Post by tinoda »

I am trying to output my image path that i have saved to the database. i need the output to be my literal images. The output I am getting is table of ID numbers which is fine but instead of images next to the ID numbers I get broken image triangles with exclamation marks. I have tried to double check my image path, absolute paths, etc but nothing is working. OK now let me give u the 2 codes, a). The one I used to save the image path b) the one i used to try retrieve the image.

the first one to save the image path to database:

Code: Select all

<?php
  $db = odbc_connect("asas","asass","asasa");
 
$sql = "INSERT INTO foto (id, url) VALUES ("
      . " 101, 'gg/Fotos/bild1.jpg')";
  $res = odbc_exec($db, $sql);
  if (!$res) {
    print("SQL statement failed with error:\n");
    print(odbc_error($db).": ".odbc_errormsg($db)."\n");
  } else {
    print("One data row inserted.\n");
  }  
 
  $sql = "INSERT INTO foto (id, url) VALUES ("
      . " 102, 'gg/Fotos/bild2.jpg')";
  $res = odbc_exec($db, $sql);
  print("One data row inserted.\n");
 
 odbc_close($db);
?>
 
the code i use to try to retrieve and see my images is as follows:

Code: Select all

<?php
  $db = odbc_connect("asas","asass","asasa");
  $sql = "SELECT id, url FROM foto";
  $res = odbc_exec($db, $sql);
 
 while ($row = odbc_fetch_array($res)) {
  print($row['id'].",<img src='".$row['url']."'>,".$row['time']."\n");
 
   }  
  
odbc_free_result($res);
 
odbc_close($db);
?>
 
The first code successfully writes everything to the database but the second code only outputs the ID number and red boxes without my images.
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: Rerieve Image path from database ---- problem please help

Post by mickeyunderscore »

Have you checked the image path actually being used? e.g. not the one in the database? Try right-clicking the broken image and select properties, this should give you the full path to the image that is being used.
tinoda
Forum Commoner
Posts: 33
Joined: Mon Dec 29, 2008 3:32 am

Re: Rerieve Image path from database ---- problem please help

Post by tinoda »

mickeyunderscore wrote:Have you checked the image path actually being used? e.g. not the one in the database? Try right-clicking the broken image and select properties, this should give you the full path to the image that is being used.
..actually thats what is making my head go round because the full path is exactly the same as the path i stored in the database.
Post Reply