无法从数据库php获取图像

时间:2019-01-15 10:23:30

标签: php html mysql pdo owl-carousel

美好的一天,我只想问一下,为什么我上次使用它时却无法从这段代码中获取图像。

这是功能

/*ADDING SECTION*/
    public function AddHomeImages($images){
        try{
            $stmt = $this->db->prepare("INSERT INTO home(image) VALUES(:images)");
            $stmt->bindParam(":images", $images);
            $stmt->execute();

            return $stmt;

        }catch(PDOException $ex){
            echo $ex->getMessage();
        }
    }

这就是我将其上传到文件夹的方式

<?php
/*---------DEVELOPMENT-----------*/
require_once '/database/database.php';


if(isset($_POST['btn-home-submit'])){
// $file = $_FILES['file'];

if(!empty($_FILES['file']['tmp_name'])){
    move_uploaded_file($_FILES['file']['tmp_name'],"images/sliding_images/" . $_FILES['file']['name']);
}else{
    //nothing
}
$location = $_FILES['file']['name'];
if($user->AddHomeImages($location)){
    header("Location: admin-index.php?uploadedsuccessfully");
}   
}

?>

现在它可以成功地将文件上传并移动到该文件夹​​以及数据库中了,我现在想使用此代码来显示它

<?php

 require_once '/database/database.php';

 $stmt = $db_con->prepare("SELECT * FROM home");
 $stmt->execute();


       <div class="owl-carousel owl-carousel-fullwidth">
                    while($userRow=$stmt->fetch(PDO::FETCH_ASSOC)){
                        echo "<div class='item'";
                        echo "<img src='images/sliding_images/" .$userRow['image']. "' alt='UTEC PHOTO'>";
                        echo "<div class='slider-copy'";
                        echo "<h2>Architecture " .$userRow['id']. "</h2>";
                        echo "</div>";
                        echo "</div>";
                    }
          </div>

?>

但是它只能得到$userRow['id']而不是图像。这是屏幕截图

enter image description here

控制台上实际上没有错误。有人帮我。

1 个答案:

答案 0 :(得分:0)

Replace part of code.

echo "<div class='item'";

With below code(missing >).

 echo "<div class='item'>";
相关问题