images in db

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
Denisem
Forum Newbie
Posts: 20
Joined: Sat May 04, 2002 8:48 am
Location: VA

images in db

Post by Denisem »

Guys,

I have an mysql db where I have stored the pathname for an image e.g. ring2.jpg.

I then use the code below to show the image, but nothing pulls up. Any idea what I am doing wrong?


echo "<img src='http://www.umuc.edu/~em680a10/";
echo $row["image"];


The url is : http://nova.umuc.edu/cgi-bin/cgiwrap/em ... oducts.php
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try:

echo "<img src='http://www.umuc.edu/~em680a10/";
echo $row["image"];
echo ">";

because i see in your images they have the <br> tag locked on ;-)
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

actually, try...

Code: Select all

echo "<img src="http://www.umuc.edu/~em680a10/" . $row&#1111;"image"] . "" border="0">";
Image Image
Denisem
Forum Newbie
Posts: 20
Joined: Sat May 04, 2002 8:48 am
Location: VA

Post by Denisem »

hob_goblin wrote:try:

echo "<img src='http://www.umuc.edu/~em680a10/";
echo $row["image"];
echo ">";

because i see in your images they have the <br> tag locked on ;-)
Thank you for your response. What do I do? close the <br> with a </br>. (byt he way tried that with the >br> in from of the image tag and it didn't work) Remove all <br> or something else?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

it does practically the same thing, but i figured since he's not using the images as links so people wouldn't have to worry about it :-)
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

If ya look at your code, you would have noticed that you forget the second ' in the 3rd line of your code. ;)
Image Image
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

no no no don't modify the <br>'s at all --
you just never closed the image tag so it looked like:

<img src=imageurl <br>
when it needed to look like
<img src=imageurl><br>
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

phice wrote:actually, try...

Code: Select all

echo "<img src="http://www.umuc.edu/~em680a10/" . $row&#1111;"image"] . "" border="0">";

try his
Denisem
Forum Newbie
Posts: 20
Joined: Sat May 04, 2002 8:48 am
Location: VA

Post by Denisem »

hob_goblin wrote:it does practically the same thing, but i figured since he's not using the images as links so people wouldn't have to worry about it :-)
Tried it, but it didn't work. Should my path be something else? In the table I only list ring2.jpg. and the pictures are located in my www directory on the unix server and copies are also in the cgi-bin directory. I have tried different variations of the img source tag below to include the www, cgi-bin, etc, but still no luck.


Here is my entire code:

#!/usr/local/bin/php
<html>
<head>
<title>Show available products</title>
</head>
<body><body bgcolor=beige>
<center><A HREF="http://nova.umuc.edu/~em680a10/diamondhome.html">Back to Php Home Page</A>.<br><br>


<h1> Jewelry to love </h1>
</center>

<?

@ $db = mysql_pconnect("localhost", "em680a10", "3s8d5m2f");

if (!$db)
{
echo "Error: Could not connect to database. Please try again later. ";
exit;
}


mysql_select_db("em680a10");

$query = "select * from products";

$result = mysql_query($query);

$num_results = mysql_num_rows($result);

echo "<P> <strong> Number of products available: </strong> ".$num_results."</p>";

for($i=0; $i<$num_results; $i++)

{


$row = mysql_fetch_array($result);

echo "<P><strong>Product Name : </strong>";

echo htmlspecialchars( stripslashes($row["name"]));

echo "<br><strong> Product Description: </strong> ";

echo htmlspecialchars (stripslashes($row["description"]));

echo "<br><strong> Price: </strong></br> ";

echo htmlspecialchars (stripslashes($row["price"]));


echo "<img src='http://www.umuc.edu/~em680a10/";
echo $row["image"];
echo ">";


echo "<br><strong> Product ID: </strong>";
echo htmlspecialchars (stripslashes($row["productid"]));

echo "</p>";

}

?>

<A HREF="http://nova.umuc.edu/~em680a10/phphome.html">Back to Php Home Page</A>.<br><br>

</body>
</html>
Denisem
Forum Newbie
Posts: 20
Joined: Sat May 04, 2002 8:48 am
Location: VA

Post by Denisem »

phice wrote:If ya look at your code, you would have noticed that you forget the second ' in the 3rd line of your code. ;)
I know this is an incredibly stupid question but where does the second ' go? At the very end of the third row befre the last "?

echo "<img src='http://www.umuc.edu/~em680a10/";
echo $row["image"];
echo ">";
Denisem
Forum Newbie
Posts: 20
Joined: Sat May 04, 2002 8:48 am
Location: VA

Post by Denisem »

hob_goblin wrote:
phice wrote:actually, try...

Code: Select all

echo "<img src="http://www.umuc.edu/~em680a10/" . $row&#1111;"image"] . "" border="0">";

try his
Hey you - it worked. I could kiss you!!!

I have spent days trying to figure this out. Thank you, thank you!!

I have some fine tuning to do with the display, but the funtionality is there.


http://nova.umuc.edu/cgi-bin/cgiwrap/em ... oducts.php
Last edited by Denisem on Tue May 07, 2002 6:06 pm, edited 1 time in total.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

heh i had the correct idea but i guess i didnt think it all out... good job phice, you made someones day :P
Post Reply