<?php
$query="SELECT * FROM Products ORDER BY id ASC";
$result=mysqli_query($connect,$query);
$image_path = "";
if(mysqli_num_rows($result)>0)
{
while($row=mysqli_fetch_array($result))
{
?>
<div class="item" style="background:white;solid lightgrey;box-shadow: 12px 12px 22px -10px #888888;">
<form action="description.php" method="post" id="item">
<div class="product">
<div class="product-thumb" name = "image" id ="image">
<?php echo '<img class="img-responsive img-fullwidth" src="data:image/jpeg;base64,'.base64_encode( $row["image"] ).'"/>' ?>
<input type="hidden" name='product_image' id="product_image"
value="<?php echo '<img class="img-responsive img-fullwidth" src="data:image/jpeg;base64,'.base64_encode( $row["image"] ).'"/>' ?>" />
//input closing tag is clashed with img to closing tag
</div>
<div class="overlay">
<button name="add_to_cart" type="submit" class="btn btn-lg btn-dark btn-theme-colored btn btn-circled text-uppercase font-weight-5" href="shop-cart.html" >Add To Cart</button>
</div>
</div>
</div>
</form>
</div>
<?php
}
}
?>
Asked
Active
Viewed 44 times
-2

aynber
- 22,380
- 8
- 50
- 63

Sagar Telangi
- 93
- 1
- 1
- 3
-
2Do not put an img tag inside of the input value. – aynber Mar 22 '19 at 14:32
-
I'm actually trying to pass image from database through hidden variable – Sagar Telangi Mar 22 '19 at 14:32
-
3You will get multiple elements with the same id. Id's _must_ be unique within the document. – M. Eriksson Mar 22 '19 at 14:33
-
Your double-quotes inside of the img tag will conflict with the double quotes surrounding the value tag. If you really want to try this, you'll need to escape them. – aynber Mar 22 '19 at 14:34
-
your value tag isn't correct – Sfili_81 Mar 22 '19 at 14:34
-
2Just send the src then – Romain B. Mar 22 '19 at 14:34
-
I recommend simplifying the code a little bit to other people help you faster and more efficiently. – Ameen Mar 22 '19 at 14:42
1 Answers
0
I think the way your sending the image to the browser and then sending it back to the server is a bad idea. I can't tell you the proper way to do it since I don't know the context to what you are doing.
However, the solution to your problem is to escape the characters in the img
tag using the htmlentities
function like this:
<input
type="hidden"
name='product_image'
id="product_image"
value="<?php echo htmlentities('<img class="img-responsive img-fullwidth" src="data:image/jpeg;base64,'.base64_encode( $row["image"] ).'"/>'); ?>" />

Ameen
- 1,747
- 3
- 16
- 31