php - 我在从数据库到页面显示图像时遇到问题

标签 php html css

我已经创建了一个具有画廊上传功能的网站。
上传完美无缺,但网页上没有显示图片。
我找不到代码中的错误

我已尝试将图像显示为我创建的框的背景图像,并带有带有属性 src 的图像标签。
最后一种方法显示网站正在读取图片,但无法显示。

    <div class="wrapper">
      <h2>Art Gallery</h2>
      <div class="Gallery-container">
        <?php
        include_once 'includes/dbh.inc.php';

        $sql = "SELECT * FROM gallery1 ORDER BY orderGallery DESC";
        $stmt = mysqli_stmt_init($conn);
        if (!mysqli_stmt_prepare($stmt, $sql)) {
          echo "SQL statement failed!";
        } else{
          mysqli_stmt_execute($stmt);
          $result = mysqli_stmt_get_result($stmt);

          while ($row = mysqli_fetch_assoc($result)) {
            echo '<a href="#">
              <div><img src=url(gallery/img/'.$row["imgfullnameGallery"].');></div>
              <h3>'.$row["titleGallery"].'</h3>
              <p>'.$row["descGallery"].'</p>
            </a>';
          }
        }


        ?>
        </div>

        <?php
        if (isset($_SESSION['username'])) {
          echo '<div class="gallery-upload">
            <form action="includes/galleryupload.inc.php" method="post" enctype="multipart/form-data">
              <input type="text" name="filename" placeholder="File name...">
              <input type="text" name="filetitle" placeholder="Title...">
              <input type="text" name="filedesc" placeholder="Description...">
              <input type="file" name="file">
              <button type="submit" name="submit">UPLOAD</button>
            </form>
          </div>';
        }

      ?>
    </div>

最佳答案

您使用了错误的语法 img 标签 请更新以下代码

while ($row = mysqli_fetch_assoc($result)) {
     echo '<a href="#">
        <div><img src="gallery/img/'.$row["imgfullnameGallery"].'"></div>
        <h3>'.$row["titleGallery"].'</h3>
        <p>'.$row["descGallery"].'</p>
     </a>';
}

关于php - 我在从数据库到页面显示图像时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56199294/

相关文章:

javascript - 一次只在搜索栏中显示 5 个结果

html - "Invalid form control"仅在谷歌浏览器中

javascript - ajax 向/从 Controller MVC 发送和获取数据

PHP 间隔与下限

php - Laravel 5 - 配置子文件夹

javascript - 使用 javascript 每周更改一次显示的日期

html - 为什么我的 Child Div 忽略它的父级?

javascript - 如何阻止 60 秒计时器成为 "jumpy"(css/javascript)

javascript - 如何使用 ng-animate 在表格行中对指定的表格数据进行动画处理?

php - 获取帖子数量最大的用户 Phalcon