将图像标题插入数据库不起作用?

时间:2018-06-07 01:39:48

标签: php mysql

好的,所以我提出了一种在我的论坛网站上传图像的方法,通过检查数据库,并将图像标题插入到数据库中。当我显示图像时,它会检查检查是否为真,如果是,则它会回显带有图像名称的html标签。我的问题是将图像标题上传到数据库中。它不会插入数据库。你能帮忙吗?

<?php
session_start();

include_once 'dbh.php';


$forum = $_SESSION['forum'];
$name = $_SESSION['username'];
$check = "true";

if (isset($_POST['submit'])){
$file = $_FILES['file'];

$fileName = $_FILES['file']['name'];
$fileTmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileError = $_FILES['file']['error'];
$fileType = $_FILES['file']['type'];

$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));

$allowed = array('jpg', 'jpeg', 'png', 'pdf', 'gif', 'bmp', 'mp4', 'avi',);

if (in_array($fileActualExt, $allowed)) {
    if ($fileError === 0) {
    if ($fileSize < 1000000000) {
        $fileNameNew = uniqid('', true) . "." . $fileActualExt;
        $fileDestination = "uploads/" . $fileNameNew;
        move_uploaded_file($fileTmpName, $fileDestination);

        $sql = "INSERT INTO $forum (name, post, image) VALUES ('$name', '$fileName', '$check');";
        $result = mysqli_query($conn, $sql);

        header("Location: display.php?success");
    } else {
        echo "your file is too big";
    }
    } else {
    echo "there was an error";
    }
} else {
    echo "you cannot upload this type of file!";
}

}

1 个答案:

答案 0 :(得分:-1)

首先将$ fileName更改为$ sql字符串中的$ fileNameNew

然后还将您的查询行更改为:

$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));

现在来自post请求的响应应该有错误。