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.
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.
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)?