【发布时间】:2019-03-22 14:30:36
【问题描述】:
<?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
}
}
?>
【问题讨论】:
-
不要在输入值内放置img标签。
-
我实际上是在尝试通过隐藏变量从数据库中传递图像
-
您将获得多个具有相同 id 的元素。 ID 必须在文档中是唯一的。
-
img 标签内的双引号将与 value 标签周围的双引号冲突。如果你真的想试试这个,你需要逃避它们。
-
然后发送 src