Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从SQL连接图像_Php_Html_Sql - Fatal编程技术网

Php 从SQL连接图像

Php 从SQL连接图像,php,html,sql,Php,Html,Sql,每次我尝试加载下面的页面时,图像都不会显示。我在SQL数据库中有图像名称,并且图像文件夹与index.php路径相同 <div class="container-fluid"> <div class="col-md-12"> <div class="row"> <div class="col-md-6&qu

每次我尝试加载下面的页面时,图像都不会显示。我在SQL数据库中有图像名称,并且图像文件夹与index.php路径相同

    <div class="container-fluid">
        <div class="col-md-12">
            <div class="row">
                <div class="col-md-6">
                    <h2 class="text-center">Products</h2>

                    <?php

                    $query = "SELECT * FROM product";
                    $result = mysqli_query($connect,$query);

                    while ($row = mysqli_fetch_array($result)) {?>
                        <form method="get" action="index.php?id=<?= $row['id'] ?>">
                            <img src="img/<?= $row['image'] ?>" style='height: 150px;'>
                            <h2><?= $row['name']; ?></h2>
                            <h2><?= $row['price']; ?></h2>

                        </form>


                    <?php }


                    ?>
                </div>
                <div class="col-md-6">
                    <h2 class="text-center">Shopping Cart</h2>
                </div>
            </div>
        </div>
    </div>

</body>
</html>

产品

我在我的电脑上尝试了这个代码,图像显示得非常完美

也许,您忘记放置连接查询

<div class="container-fluid">
    <div class="col-md-12">
        <div class="row">
            <div class="col-md-6">
                <h2 class="text-center">Products</h2>

                <?php

                $connect = mysqli_connect('localhost','root','','test');

                
                $query = "SELECT * FROM product";
                $result = mysqli_query($connect,$query);

                
                while ($row = mysqli_fetch_array($result)) {?>                      
                    <form method="get" action="index.php?id=<?= $row['id'] ?>">
                        <img src="img/<?= $row['image'] ?>" style='height: 150px;'>
                        <h2><?= $row['name']; ?></h2>
                        <h2><?= $row['price']; ?></h2>

                    </form>


                <?php }


                ?>
            </div>
            <div class="col-md-6">
                <h2 class="text-center">Shopping Cart</h2>
            </div>
        </div>
    </div>
</div>

产品

有什么错误吗?您是否进行过var_转储($row);看看数据是否存在?html是什么样子的?