首页 > 解决方案 > 结束标签与结束标签冲突

问题描述

<?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
    }
}
?>

标签: phphtml

解决方案


我认为您将图像发送到浏览器然后将其发送回服务器的方式是一个坏主意。我不能告诉你正确的方法,因为我不知道你在做什么的上下文。

但是,您的问题的解决方案是img使用如下函数转义标签中的字符htmlentities

<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"] ).'"/>'); ?>" />

推荐阅读