Reputation: 25
I must say that i'm a real beginner in this so keep that in mind. I'm currently working on a local server here and my problem here is that i'm trying to add a picture to my php code and don't really know if the problem come from mysql or from the actual code.
in mysql it's a varchar of 200 and it's named: products_image
And my code look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Releases</title>
</head>
<body>
<?php
require 'database_connection.php';
$select_query = "SELECT * FROM releases";
$result = mysql_query($select_query);
if ($result) {
$row = mysql_fetch_array($result);
$products_name = $row['products_name'];
$products_title = $row['products_title'];
$products_description = $row['products_description'];
$products_image = $row['products_image'];
} else {
die("Error locating user with ID {$user_id}");
}
echo"{$products_name} {$products_title} {$products_description} ";
echo "<img src=\"$products_image.\">";
?>
</body>
</html>
And when i look at my source code it show me this for the image part:
<img src="C:\wamp\www\chaosruralenew\images\kalsahnikovdreams.jpg.">
Thanks for you help.
Upvotes: 0
Views: 1158
Reputation: 534
It is best to use the html
tags outside the PHP
code, by the way try this I hope it will work
<img src="images/<?php echo $row['products_image']; ?>"/>
save the image name with .jpg
or any other valid extension of image in data base and retrieve it and display the image.
In this situation you don't need to take care of the path for the images. I tried this and it is working for me very well.
Upvotes: 0
Reputation: 34054
Looks like you have an erroneous period:
echo "<img src=\"$products_image.\">";
^
Few other notes on your code:
mysql_
functions have been deprecated. Learn about PDO or MySQLi - this article will help you decide which.mysql_error
after your function.<img>
may require a trailing slash <img ... />
Upvotes: 1
Reputation: 2255
You are using a local path to the server filesystem.
You should save the path relative to your website robot.
chaosruralenew/images/kalsahnikovdreams.jpg
Upvotes: 0