Forum Moderators: coopster

Message Too Old, No Replies

Displaying an image from the db?

This should be easy, right?

         

freshrod

7:04 am on May 22, 2006 (gmt 0)

10+ Year Member



I have users store an image url in the DB, and then I'm trying to recall it to display. I've checked the DB and the url is in there, so I must be doing something wrong in the php I guess.

here's the query:

$result = mysql_query("SELECT * FROM users WHERE userId = '$alumni'");

here's the code:

print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Picture:</td><td><img src='{$row['pic_url']}'></td></tr>";

obviously in a table, but there are other filds with the same syntax that are displayed fine.

Not sure what the deal is.

dreamcatcher

7:16 am on May 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using mysql_fetch_array?

If not your query needs to be:

$result = mysql_query("SELECT * FROM users WHERE userId = '$alumni'");
$row = mysql_fetch_array($result);

dc

topr8

7:20 am on May 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



are you storing the full path of the image url in the db?

what does the source of the actual rendered page read as?

freshrod

5:52 pm on May 22, 2006 (gmt 0)

10+ Year Member



Yes, and yes.

The full code is like this:

displayUserInfo($result);

function displayAlumInfo($result) {

while ($row = mysql_fetch_array ($result))
{
print "\n<tr>\n\t<td width='25%' bgcolor='#BCD2EE'>Picture:</td><td><img src='{$row['pic_url']}'></td></tr>";
etc, etc, etc...

I'm storing the full url, like: [mydomain.com...] <--- not a real link

nfs2

6:02 pm on May 22, 2006 (gmt 0)

10+ Year Member



Maybe try

$pic = $row['pic_url'];
print '\n<tr>\n\t<td width="25%" bgcolor="#BCD2EE">Picture:</td><td><img src="'.$pic.'"></td></tr>';

freshrod

6:27 pm on May 22, 2006 (gmt 0)

10+ Year Member



Thanks for the input guys. I tried the last suggestion, but have also noticed something. When I enter the file extention (.jpg in this case) it cuts it off. is that something in my security? I'm passing these variables through some code to add slashes and take out html entities:

Here's the code for that:
array_pop($_POST);
if ( get_magic_quotes_gpc() == 1 ) {
// strips slashes if magic quotes is on
// required for use with m_r_e_s()
// returns $_POST with all values stripped of slashes
$_POST= array_map('stripslashes', $_POST);
}

foreach ( $_POST AS $key => $value ) {
/*
assigns a variable name for each POST index
returns the value run through htmlentities & m_r_e_s
*/
$$key = htmlentities(mysql_real_escape_string($value));
}

Otherwise I'm not sure why it would strip the file extension.

san_garrafa

10:42 pm on May 22, 2006 (gmt 0)

10+ Year Member



It seems that your field is not long enough to fit your data, maybe that's why the image extension is missing. Check your table definition.

freshrod

3:09 pm on May 23, 2006 (gmt 0)

10+ Year Member



lol... that was the problem. Man, thlk about over-analysing the problem. I feel stupid now.