【问题标题】:<input> closing tag clashed with <img> closing tag [duplicate]<input> 结束标签与 <img> 结束标签冲突 [重复]
【发布时间】: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

标签: php html


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2014-07-29
    • 2016-02-20
    • 2014-04-22
    • 2023-03-12
    • 2012-03-20
    • 2017-10-04
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多