Forum Moderators: coopster

Message Too Old, No Replies

newbie question RE: <img src=...>

         

lazarus

1:18 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



i am scripting a small news management system, and i am having probs showing images on the "story" page.

on the admin page, they can add a title, taster, full story and an image. the image name is stored in a sql database as text, and i want to use the "img src" code to pull the file name from the database and view the picture. any ideas?

benihana

1:32 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sounds fine to me. what exactly are you having trouble with?

lazarus

1:48 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



its just comes up with the pic not found box. with the red cross. this is a code snippet.

// generate and execute query
$id= $_GET['id'];
$query = "SELECT title, taster, full, pic, timestamp FROM news WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());

// get resultset as object
$row = mysql_fetch_object($result);

// print details
if ($row)
{
?>
<p>
<b><? echo $row->title;?></b>
<p>
<font size="-1"><? echo nl2br($row->taster);?></font>
<br />
<font size="-1"><? echo nl2br($row->full);?></font>
<br />
<img src="<? echo ($pic);?>">
<br />
<font size="-2">This press release was published on <? echo formatDate($row->timestamp);?>.</font>
<?
}
else
{
?>
<p> <font size="-1">That press release could not be located in our database.</font>
<?
}
// close database connection
mysql_close($connection);

?>
<p align="center"><a href="list.php">Back</a>
</body>
</html>

the database columns is called pic.

ukgimp

1:53 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does this:
<img src="<? echo ($pic);?>">

actually print out the pic name. Can you test is by echoing as text on the page so you at least know it is being passed.

Have you checked the paths.

Not much insight there but it might point you in the right direction.

Cheers

lazarus

1:58 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



i can pass it as text. how would i point it to the right dir?

benihana

2:02 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



either store the dir in the database with the image name, or have all images in the same dir and ues:

<img src="directory/<? echo ($pic);?>">

lazarus

2:09 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



i'd prefer to use just the one directory, but it still comes up with the red cross. i'm prolly being really thick.

i'll keep playing, if you have any more suggestions i'll be glad to hear them.

cheers for your help.

dave

benihana

2:13 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



probably a dumb question but are you remembering to add the extension to the image names? ;)

lazarus

2:16 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



the extension is saved in the database as part of the name. so it should be alright.

would it be easier if i posted the relevent pages of code, or even a zip of my files?

benihana

2:25 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what doctype are you using?
looking at the original snippet, you have unclosed <p> tags, and xhtml style <br /> tags.

in this discussion [webmasterworld.com] someone mentions the <br /> tags can cause probalems when used in pure html docs

ShawnR

2:33 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Lazarus & welcome to WebmasterWorld.

Go to the red x and look at the properties. How you do that depends on your browser; but in most cases, right click and select properties. Have a look at the path the browser is looking for the pic in, and compare that with the path the pic really is in.

You can't post a zip of your files, and it is not advisable to post the complete relevant pages. You can post short samples or snippets, so cut down your code to the bare minimum to show the problem, and make sure that you have removed any specific urls before posting it.

Shawn

lazarus

2:45 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



hi shawn and thanks.

when i use the code:

// print details
if ($row)
{
?>
<p>
<b><? echo $row->title;?></b>
<p>
<font size="-1"><? echo nl2br($row->taster);?></font>
<br />
<font size="-1"><? echo nl2br($row->full);?></font>
<br />
<img src=images/"<? echo ($pic);?>">
<br />
<font size="-2">This press release was published on <? echo formatDate($row->timestamp);?>.</font>

its gives me the path [blah...]

for whatever reason it won't replace the "" with the filename.

lazarus

3:02 pm on Jun 11, 2003 (gmt 0)

10+ Year Member



done it! thanks for all your help guys.

i replaced:

<img src=images/"<? echo ($pic);?>">

with
<img src=images/<? echo nl2br($row->pic);?>></img>

later guys!

ShawnR

11:17 pm on Jun 11, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ouch... That was me kicking myself. Sorry i didn't see it. Well done for finding it.