gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 21:14:22 25 4
gpt4 key购买 nike

我已经编写 PHP 代码 2 周了(这不太漂亮),但我一直无法找到我的问题的答案。我希望管理员类型的用户能够填写表单并将其发布到基础级别用户可以查看内容的页面。我已经让所有这些都像魅力一样工作,但我的困境是允许管理员用户也包含图像。也许我只是不知道要搜索什么。

这是管理用户页面的 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];
}

?>

这是基本级别用户页面的代码:(我注释掉了我希望显示管理员图像的图像 block 。

 <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 + 我编写代码的时间还不够长,无法真正自己解决问题。

最佳答案

您可以将所有用户图像保存在一个文件夹(我们称之为/images/user)下,并将文件名记录到数据库中。

if ($_POST['submit']) {
$title = $_POST['title'];
$deadline = $_POST['deadline'];
$content = $_POST['content'];
$logoname = basename($_FILES["fileToUpload"]["logoname"]; // <-- Make sure your form is ready to submit an file
// Update below as per your need.
$target = 'images/users/' . $logoname;
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target);

$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>";
}

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

<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>

关于php - 如何包含与用户数据库信息相关的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36093257/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com