How do you call in an image from database?

I have tried using this code

  <img src="<?php echo $values["image"]; ?>">

but it isnt working

You don’t. You want the url or path to that image, not the image itself.

so i make another php script just for image?

No,

$values[“image”]

should return the image and path.

like this?
$values=mysqli_query($connect,“SELECT images FROM product2”);
idk why i asked but it still not working

When you use that query, what is returned?

the images? im not so sure myself or should i make another db for images only

normally you store the file name (and perhaps part of the path) in the db and the actual files in the file system.

I did, it is with the product names and prices but how do i call it off to put into php?

Where is the filename stored? Where is the image stored on the server?

Here

Based on that, it means your images would be giving the following for the img elment,

<img src="images/product-1.jpg">

So, if the file is executing from root AND the image directory is in root, that should work. If it isn’t, then you need to add the rest of the path on to that.

<img src="/images/product-1.jpg">

Maybe?

nah if i change it to

<img src="/images/product-1.jpg">

then images from my products does not show up cause i get them into database

i want both of them to get it from the same database

You aren’t storing the image in the database. Based on what the database shows, you are storing the path (images/product.jpg). If the files don’t exist in that directory somewhere, the images aren’t on the server. How you are doing it is correct, it’s just a matter of linking where those images are to where they need to be shown.

How about something like:

$query="SELECT pname, image, price FROM product2 WHERE pname=‘Artsy Coffee’ “;
$result=mysqli_query($handle, $query);
$row=mysqli_fetch_assoc($result);
$product=$row[‘pname’];
$image=$row[‘image’];
$price=$row[‘price’];
echo(”
<table>
<tr>
<td> $product </td>
</tr>
<tr>
<td> <img src=’$image’> </td>
</tr>
<tr>
<td> $price </td>
</tr>
</table>
");

Sponsor our Newsletter | Privacy Policy | Terms of Service