数据库phpmyadmin上的图像路径不起作用

时间:2018-08-05 09:43:50

标签: php mysql phpmyadmin

我尝试在mysql上插入一些数据,然后在图像列中输入图像 路径并保存,当我尝试选择要显示在框架上的图像时 iframe为空白,无图像显示,希望您能帮助我解决问题。

这里我用来选择图像的代码:

<?php 

include_once('connection.php');

$sql = "select * from student_att order by number DESC limit 1";
$result = mysqli_query($conn,$sql);
while( $row = mysqli_fetch_array($result)) {

         $id1=$row['id'];
         $name1=$row['name'];
          $course1=$row['course'];
          $purpose1=$row['purpose'];
        $image=$row['image'];
   }
?>

这是我的iframe代码:

<iframe  style="width:70%; margin-top:40px; padding-left:100px; margin-right:20px;  height:380px; border-radius:20px;
        border-color:#CCCCCC;  border-style: solid;"><img src="<?php echo $row['image'];?>"></iframe>

这是我的html代码:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <title>Material Design Visitor Form</title>
  <!-- Font Awesome -->
 <link rel="stylesheet" href="font-awesome-4.7.0/css/font-awesome.min.css">
  <!-- Bootstrap core CSS -->
  <link href="css/bootstrap.min.css" rel="stylesheet">
  <!-- Material Design Bootstrap -->
  <link href="css/mdb.min.css" rel="stylesheet">
  <!-- Your custom styles (optional) -->
  <link href="css/style.min.css" rel="stylesheet">
 <style type="text/css">
    @media (min-width: 800px) and (max-width: 850px) {
            .navbar:not(.top-nav-collapse) {
                background: #1C2331!important;
            }
        }

    .input-group .form-control.added-padding-2 {
    padding-top: 4px;
}
.input-group .form-control.added-padding-3 {
    padding-top: 3px;
}   
.card{
background-color: rgba(255,255,255,0.85);
width:80%;
margin-left:100px;
}   

  </style>
</head>

<body>
  <div class="view" style="background-image: url('images/demo/backgrounds/683661084.png'); background-repeat: no-repeat; background-size: cover;">
<div class="mask rgba-black-light d-flex justify-content-center align-items-center">
<div class="col-md-12 col-lg-4 offset-lg-1 text-center  margins">
                        <div class="white-text">
                         <iframe  style="width:70%; margin-top:40px; padding-left:100px; margin-right:20px;  height:380px; border-radius:20px;
        border-color:#CCCCCC;  border-style: solid;"><img src="./<?php echo $image;?>"></iframe>
                            <h1 class="h1-responsive rgba-black-light intro-title font-weight-bold mt-sm-5 mt-0 mb-4  wow fadeInLeft animated" data-wow-delay="0.3s" style="visibility: visible; animation-name: fadeInLeft; animation-delay: 0.3s;">Valid Entry<i class="fa fa-check green-text"></i></h1><hr class="hr-light my-4">
                    </div>

                    </div>
                    <div class="col-xl-5 col-lg-6 col-md-10 col-sm-12 mx-auto mt-lg-5">
                            <div class="card wow fadeInRight animated" data-wow-delay="0.3s" style="visibility: visible; animation-name: fadeInRight; animation-delay: 0.3s;">
                                <div class="card-body">
                                 <h3 class="dark-grey-text text-center">
                    <strong><i class="fa fa-info-circle blue-text"></i> Student Info:</strong>
                  </h3>
                  <hr> 
                             <div class="md-form mb-0" >
                                        <i class="fa fa-lock prefix "></i>
                                        <input type="text" id="id1" name="id1"class="form-control" value="<?php echo $id1;?>" readonly="true">
                                        <label for="orangeForm-name">ID</label>
                                    </div>
                                    <div class="md-form mb-0" >
                                        <i class="fa fa-user prefix "></i>
                                        <input type="text" id="name1" name="name1" class="form-control" value="<?php echo $name1;?>" readonly="true">
                                        <label for="orangeForm-email">Name</label>
                                    </div>

                                    <div class="md-form mb-0" >
                                        <i class="fa fa-book prefix "></i>
                                        <input type="text" id="course1" name="course1" class="form-control" value="<?php echo $course1;?>" 
                                        readonly="true">
                                        <label for="orangeForm-pass">Course</label>
                                    </div>
                                     <div class="md-form mb-0" >
                                        <i class="fa fa-check-square-o prefix "></i>
                                        <input type="text" id="purpose1" name="purpose1" class="form-control" value="<?php echo $purpose1;?>" 
                                        readonly="true">
                                        <label for="orangeForm-pass">Purpose</label>
                                    </div>
                                     </div>
                            </div>
                        </div>
      </div>
   </div>
  <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
  <!-- Bootstrap tooltips -->
  <script type="text/javascript" src="js/popper.min.js"></script>
  <!-- Bootstrap core JavaScript -->
  <script type="text/javascript" src="js/bootstrap.min.js"></script>
  <!-- MDB core JavaScript -->
  <script type="text/javascript" src="js/mdb.min.js"></script>
  <!-- Initializations -->
  <script type="text/javascript">
    // Animations initialization
    new WOW().init();
  </script>

<script>

setTimeout(function(){ window.location = "studform.php" },4000);
</script>
</body>

</html>

这是我在phpmyadmin上使用的路径,我将列图像设置为varchar:

enter image description here

2 个答案:

答案 0 :(得分:0)

我认为我发现您的代码有误。试试这个:

<iframe  style="width:70%; margin-top:40px; padding-left:100px; margin-right:20px;  height:380px; border-radius:20px;
    border-color:#CCCCCC;  border-style: solid;"><img src="<?php echo $image;?>"></iframe>

$row['image']替换为$image,因为$ row参数无法在html代码中访问,只能在循环中访问

下面您应该尝试:

<?php 

include_once('connection.php');

$sql = "select * from student_att order by number DESC limit 1";
$result = mysqli_query($conn,$sql);
$image = "";
while( $row = mysqli_fetch_array($result)) {

         $id1=$row['id'];
         $name1=$row['name'];
          $course1=$row['course'];
          $purpose1=$row['purpose'];
        $image=$row['image'];
   }
?>
<iframe  style="width:70%; margin-top:40px; padding-left:100px; margin-right:20px;  height:380px; border-radius:20px;
    border-color:#CCCCCC;  border-style: solid;"><img src="<?php echo $image;?>"></iframe>

答案 1 :(得分:0)

通常该图像不可访问或不存在。

如果使用任何框架,可能会有一些帮助程序来获取“ base_url”以生成文件完整的URL。

要使用iframe,您需要为iframe内容创建一个文件,然后将其添加到所需的页面,例如:

index.html
images /
        php.png
iframe-content.html

index.html

<iframe src="iframe.html"
    style="width:70%;
    margin-top:40px;
    padding-left:100px;
    margin-right:20px;
    height:380px;
    border-radius:20px;
    border-color:#CCCCCC;
    border-style: solid;">

iframe.html

<img name="image"  id="image" src="images/php.png">