Display images on PHP website page

Hi I’m new to PHP, at the moment I have to create an ecommerce website and I’m having trouble displaying the images on the products page I have a table called products and in the table is a column called img which has the direct path to the image for example C:/xampp/htdocs/Online_Shopping/Online_Shopping/itempics/1.jpg is one variables in the img colum , but whenever I run the page no images are displayed however the product price and name are displayed here’s my code.

  <div><br/><center><h2><font face="Lucida Handwriting" size="+1" color="blue">Apple Desktops</font></h2></center></div>
  <div style="width:100%;float:left" >
    $sel=mysql_query("select * from products where catg='$catg' and subcatg='$subcatg'");
    echo"<form method='post'><table border='0' align='center'><tr>";
echo "<tr>";
    echo "
    <td height='280' width='240' align='center'><img src=$i' height='200' width='200'><br/>
    <br><br><a href='index.php?con=12 & product_id=$i'><img src='images/MetalPlakDa5new.gif' width='70' height='20'/></a>
       <a href='index.php?con=14 & product_id=$i'><img src='images/view7.jpg' width='70' height='20'/></a>
  echo "</tr></table>
 <marquee behavior="scroll"  dir="ltr" align="absbottom">
 <img src="usepics/apple.jpg" width="100" height="70"/>
 <img src="usepics/dell.jpg" width="100" height="70"/>
 <img src="usepics/len.jpg" width="100" height="70"/>
 <img src="usepics/hp.jpg" width="100" height="70"/>

Hi @jamesnswart

Welcome to the forums. I’m sorry to say your HTML and PHP code is so dated you really need to start from scratch.

A good place to learn PHP is using

You have to bear in mind that when you output the image source, it needs to be the path relative to whatever your web site root path is when you run code from a server such as Apache. So it wouldn’t start with "C:" for a start, as this is an absolute PC-based path, and a web server normally won’t allow users access to the file system directly. Have a read up on absolute vs. relative path names, web servers have a “virtual root” which is several levels down from an actual root directory, for security reasons at the very least.

Looking later in your code, you have some other images where the path starts with “usepics” - are your database images in the same folder, or is the “itempics” folder at the same level as “usepics”? If so, that should be the start of the path name.

If you’re new to PHP, now is the time to stop using the old-style mysql library functions (such as mysql_query) to access the database. They’re not in the latest version of PHP, you should look at using PDO instead.

1 Like

You should maybe first have a refresher with HTML and something called CSS.
That code is so old it’s unreal. If you are new to this, learn new code.

The usepics and item pics are in the same folder and the usepics display when the page is run

But what is the path you have stored in the database?
Is it the full path, like C:/xampp/htdocs/Online_Shopping/Online_Shopping/itempics/
Or relative to the site root (which it should be)?

It’s the full path

So assuming that htdocs is your site root, try starting the path from Online_Shopping/

And please update that code to something that belongs in this millennium.

Well, that’s because you use the correct relative URLs for the usepics images, and don’t for the item pics.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.