我无法将变量上传到数据库

我尝试将视频文件名和其他变量上传到数据库,但是insert语句不起作用。无论如何,视频文件名和缩略图文件名都已上载到正确的文件夹。很抱歉打扰您所有的错误处理。 我已经检查过了,sql语句没有任何问题。但是为什么它不起作用? PHP代码:

<?php

    session_start();

if (isset($_POST['submit'])) {

    $videoName = $_POST['videoName'];
    $videoDesc = $_POST['description'];
    $category = $_POST['category'];
    $level = $_POST['level'];
    $userId = $_SESSION['userId'];

    $videoFile = $_FILES["videoFile"];
    $videoFileName = $videoFile['name'];
    $videoFileType = $videoFile['type'];
    $videoFileTempName = $videoFile['tmp_name'];
    $videoFileError = $videoFile['error'];

    $videoFileExt = explode(".", $videoFileName);
    $videoFileActualExt = strtolower(end($videoFileExt));
    $videoAllowed = array("mp4", "mov", "avi");

    $thumbFile = $_FILES["thumbnail"];
    $thumbFileName = $thumbFile["name"];
    $thumbFileType = $thumbFile["type"];
    $thumbFileTempName = $thumbFile["tmp_name"];
    $thumbFileError = $thumbFile["error"];

    $thumbFileExt = explode(".", $thumbFileName);
    $thumbFileActualExt = strtolower(end($thumbFileExt));
    $thumbAllowed = array("jpg", "jpeg", "png");





    if (in_array($videoFileActualExt, $videoAllowed)) {
        if(in_array($thumbFileActualExt, $thumbAllowed)) {
            if ($videoFileError === 0) {
                if ($thumbFileError === 0) { 

                            $videoFullName = $videoFile . "." . uniqid("", true) . "." . $videoFileActualExt;
                            $videoFileDestination = "../video/" . $videoFullName;

                            $thumbFullName = $thumbFile . "." . uniqid("", true) . "." . $thumbFileActualExt;
                            $thumbFileDestination = "../thumbnail/" . $thumbFullName;


                            include 'dbh.inc.php';

                            if(empty($videoName) or empty($videoDesc)) {
                                header("Location: ../uploadVideo.php?upload=empty");
                                exit();
                            } else {
                                    move_uploaded_file($videoFileTempName, $videoFileDestination);
                                    move_uploaded_file($thumbFileTempName, $thumbFileDestination);

                                $sql = "INSERT INTO video (filnavn, thumbnail, videoName, descript, idMusician, categoryName, idLevel) VALUES ('$videoFullName', '$thumbFullName', '$videoName', '$videoDesc', $userId, '$category', $level);";
                                mysqli_query($conn, $sql);

                                    header("Location: ../uploadVideo.php?upload=success");
                                    exit();
                                }

                } else {
                    echo "You had a thumbnail error!";
                    exit();
                }
            } else {
                echo "You had a video error!";
                exit();
            }
        } else {
            echo "You need to upload a proper thumbnail file type";
            exit();
        }
    } else {
        echo "You need to upload a proper video file type!";
        exit();
    }
} else {

}
评论
  • BOX07
    BOX07 回复

    You cannot insert or in this way in the if() condition, you must always use the logical operator as

     if(empty($videoName) || empty($videoDesc))
    
    

    因此,此时您的代码执行必须已经停止。