如何包含与用户数据库信息相关联的图像?

时间:2016-03-18 20:02:27

标签: php mysql file-upload mysqli

我已经用PHP编写了两个星期(它不是很漂亮)而且我无法找到问题的答案。我希望管理类型用户能够填写表单并将其发布到基本级用户可以查看内容的页面。我已经把所有这些都变成了一种魅力,但我的困境是允许管理员用户也包含一个图像。也许我只是不知道要搜索什么。

以下是管理员用户页面的php代码和表单:

<?php
error_reporting(E_ALL & ~E_NOTICE);
session_start();

include_once("connection.php");

if (isset($_SESSION['adminid'])) {
$adminid = $_SESSION['adminid'];
$adminemail = $_SESSION['adminemail'];

if ($_POST['submit']) {
    $title = $_POST['title'];
    $deadline = $_POST['deadline'];
    $content = $_POST['content'];


        $sql_blog = "INSERT INTO blog (title, deadline, content, logoname)     VALUES    ('$title', '$deadline', '$content', '$logoname')";

        $query_blog =  mysqli_query($dbcon, $sql_blog);
        echo "<script>alert('Your inquiry has been posted')</script>";
    }

} else {
    header('Location: index.php');
    die();
}

$sql = "SELECT adminid, adminemail, adminpassword, adminname FROM admin WHERE     adminemail = '$adminemail' LIMIT 1";

$query = mysqli_query($dbcon, $sql);

if ($query) {
    $row = mysqli_fetch_row($query);
    $adminname = $row[3];
}

?>

以下是基本级用户页面的代码:(我注释掉了我想要显示管理员图像的图像块。

 <main>
  <div class="container">
    <div class="row topbuffpost">
        <h1>business inquiries</h1>
        <hr>
        <?php  
        include_once('connection.php');

        $sql = "SELECT * FROM blog ORDER BY id DESC";
        $result = mysqli_query($dbcon, $sql);

        while ($row = mysqli_fetch_array($result)) {
            $title = $row['title'];
            $content = $row['content'];
            $date = strtotime($row['deadline']);

        ?>

            <div class="col-md-4 col-lg-3">
              <div class="card hoverable">

              <!--  <div class="card-image">
                  <div class="view overlay hm-white-slight z-depth-1">

                    <img src="">
                        <a href="#">
                            <div class="mask waves-effect">
                            </div>
                        </a>
                  </div>
                 </div> -->

                    <div class="card-content">
                        <h5> <?php echo $title; ?> <br/> <h6>Deadline |<small> <?php echo date("j M, Y", $date); ?> </small> </h6></h5> <br/>

                        <p> <?php echo $content; ?> </p>
                        <div class="card-btn text-center">
                            <a href="#" class="btn btn-info blue-grey darken-2 btn-md waves-effect waves-light">Read more</a>
                            <a href="#" class="btn btn-primary btn-md waves-effect waves-light"><i class="fa fa-lightbulb-o"></i>&nbsp propose a plan</a>
                        </div>
                    </div>
              </div>
            </div>
        <?php
            }
        ?> 

    </div>
  </div>

</main>

所有这一切都很完美,我无法弄清楚如何以与标题,截止日期和内容相同的方式显示图像。 Youtube也没有帮助,太多过时的php +我没有足够长的编码来自己解决问题。

1 个答案:

答案 0 :(得分:0)

您可以将所有用户图像保存在文件夹下(让我们调用<main> <div class="container"> <div class="row topbuffpost"> <h1>business inquiries</h1> <hr> <?php include_once('connection.php'); $sql = "SELECT * FROM blog ORDER BY id DESC"; $result = mysqli_query($dbcon, $sql); while ($row = mysqli_fetch_array($result)) { $title = $row['title']; $content = $row['content']; $date = strtotime($row['deadline']); $logoname = 'images/user/' . $row['logoname']; ?> <div class="col-md-4 col-lg-3"> <div class="card hoverable"> <div class="card-image"> <div class="view overlay hm-white-slight z-depth-1"> <img src="<?php echo $logoname; ?>"> <a href="#"> <div class="mask waves-effect"> </div> </a> </div> </div> <div class="card-content"> <h5> <?php echo $title; ?> <br/> <h6>Deadline |<small> <?php echo date("j M, Y", $date); ?> </small> </h6></h5> <br/> <p> <?php echo $content; ?> </p> <div class="card-btn text-center"> <a href="#" class="btn btn-info blue-grey darken-2 btn-md waves-effect waves-light">Read more</a> <a href="#" class="btn btn-primary btn-md waves-effect waves-light"><i class="fa fa-lightbulb-o"></i>&nbsp propose a plan</a> </div> </div> </div> </div> <?php } ?> </div> </div> </main> )并将文件名记录到数据库中。

   -Tbss=org
   -Tdata=org
   -Ttext=org
       Same as --section-start, with ".bss", ".data" or ".text" as the section name.

然后,您可以在页面上显示图像

while