I am storing the images in a folder on my webserver and adding the location/details of the image to the database.

But I have problems retrieving them, please help!

Is this the code I should be using?

<?php echo "<img src='/images/". $filename ."'>" ?>

then $filename is supposed to be the field name
and entries would be just "product1.jpg" "product2.jpg" & so on??

<?php echo "<img src='/images/". $filename ."'>" ?>

in this line the / before the images,Is is must???i think no..
And also make sure that is correct path of your current folder to images folder...
or echo $filename; check it with correct path of stored image..
or post your appropriate code..
i will check it..

Thank you for your help, I cant echo filename using $filename.. Why is that so?

I can do it with <?php echo $row_feat['filename'] ?> though.

newq is the database name.
I have 2 tables inside currently, the one I'm working on is Feat.

id INT auto_increment primary key
filename VARCHAR(255)
name VARCHAR(50)

<?php require_once('Connections/newq.php'); ?>
<?php
mysql_select_db($database_newq, $newq);
$query_Feat = "SELECT * FROM featured";
$Feat = mysql_query($query_Feat, $newq) or die(mysql_error());
$row_Feat = mysql_fetch_assoc($Feat);
$totalRows_Feat = mysql_num_rows($Feat);
?>

Im able to echo the name with this: <?php echo $row_Feat['name']; ?> but the filename?

hello..
i mean echo $filename; means check that image path for your current working directory...

<?php echo $filename; ?>
Is this what you're asking me to do? It doesnt work.
filename is a field in a table (feat) IN a database(newq).

Thank you and sorry I will need your patience. :)


I'm just doing this in Dreamweaver using the Application bindings >_<
Is that why <?php echo $row_Feat; ?> works. and $filename doesn't?

Sorry, I mean I tried this.

<?php echo '<a href="http://google.com">'<img src="'.$path.$row_Feat['filename'].'">'</a>' ?>

>_<

<?php echo '<a href="http://google.com">'<img src="'.$path.$row_Feat['filename'].'">'</a>' ?>

Well you closed your quotes without using the . operator.

Maybe try

<?php echo "<a href='http://google.com'><img src='{$path}{$row_Feat['filename']}' /></a>" ?>

By the way just in case you didn't know

$Name="Rob";
echo "Hello my name is $Name"; will display --> Hello my name is Rob
echo 'Hello my name is $Name'; will display --> Hello my name is $Name

Single Quotes are treated as litereal in PHP, and will display exactly what is inside them and display the varible name eg $Name instead of Rob This also means Single Quotes are better for output that does not have variables in it, because it is parsed faster.

Double Quotes are better when putting variables inside strings

Also the {} operators are a way to put variables inside of strings without having to use the . operator all the time.

That was helpful, thank you very much.

But now that I am linking it to an ID, it's still wrong?

<?php echo "<a href='products.php?id=<?php echo $row_Feat['id']; ?>'><img src='{$path}{$row_Feat['filename']}' /></a>" ?>

Error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

That was helpful, thank you very much.

But now that I am linking it to an ID, it's still wrong?

<?php echo "<a href='products.php?id=<?php echo $row_Feat['id']; ?>'><img src='{$path}{$row_Feat['filename']}' /></a>" ?>

Error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Hi,

I too am having problems uploading/ downloading and displaying images. I am new to PHP and MySQL, but have managed everything else up to this point reasonably well.

I have images stored in a subfolder of my root folder (/images/uploads) and I have a table in my database called uploads with name, type, size and file_path fields. I just can't find how to query this in php to either:

a)show me the images in a browser
or
b)upload images to the directory, and file path to the database from a browser.

Please could someone help me here and be very specific also. I am not overly familiar with php/ mySQL functions.

Many many thanks in advance,

James

Member Avatar for rajarajan2017
echo "<img src=\"$snippet_theme/img/error.gif\" title=\"Error\" alt=\"Error\" />";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.