简体   繁体   English

mysqli_stmt_prepare失败,但是文件上传到phpmyadmin

[英]mysqli_stmt_prepare fails but file is uploaded to phpmyadmin

I have this php photo gallery, however my "mysqli_stmt_prepare" statement seems to be failing in someway. 我有这个php图片库,但是我的“ mysqli_stmt_prepare”语句似乎在某种程度上失败了。 However, when I check my DB, the files that are in accordance to the upload rules, I created in my code, have been uploaded. 但是,当我检查数据库时,已经上传了我在代码中创建的符合上传规则的文件。

The message I get each time I upload a file to the DB is the one corresponding to a failed "mysqli_stmt_prepare", namely as in the code: 每次将文件上传到DB时收到的消息是与失败的“ mysqli_stmt_prepare”相对应的消息,即在代码中:

echo "SQL statement failed! 1" 回显“ SQL语句失败!1”

<?php

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

    $newFileName = $_POST['filename'];
    //sets the file name to "gallery"
    if (empty($_POST['filename'])) {
      $newFileName = "gallery";
    //adds hyphens to empty spaces
    } else {
      $newFileName = strtolower(str_replace(" ", "-", $newFileName)); 
    }

    $imageTitle = $_POST['filetitle'];
    $imageDesc = $_POST['filedesc'];

    $file = $_FILES['file'];

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

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

    $allowed = array("jpg", "jpeg", "png", "pdf");

    if (in_array($fileActualExt, $allowed)) {
      if ($fileError === 0) {
        if ($fileSize < 200000) {
          $imageFullName = $newFileName . "." . uniqid("uniqID", false) . "." . $fileActualExt;
          $fileDestination = "../gallery/" . $imageFullName;


          include_once "dbh.inc.php";

          if (empty($imageTitle || $imageDesc)) {
            header("Location: ../gallery.php?upload=empty");
            echo "You didn't include the Image Title and Image description!";
            exit();
          } else {
            $sql = "SELECT * FROM gallerytrexatek";
            $stmt = mysqli_stmt_init($conn);
            if (!mysqli_stmt_prepare($stmt, $sql)) {
              echo "SQL statement failed! 1";
            } else {
              mysqli_stmt_execute($stmt);
              $result = mysqli_stmt_get_result($stmt);
              $rowCount = mysqli_num_rows($result);
              $setImageOrder = $rowCount + 1;

              $sql = "INSERT INTO gallery (titleGallery, descGallery, imgFullNameGallery, orderGallery) VALUES (?, ?, ?, ?);";
              if (!mysqli_stmt_prepare($stmt, $sql)) {
                echo "SQL statement failed! 2";
              } else {
                mysqli_stmt_bind_param($stmt, "ssss", $imageTitle, $imageDesc, $imageFullName, $setImageOrder);
                mysqli_stmt_execute($stmt);

                move_uploaded_file($fileTempName, $fileDestination);

                header("Location: ../galleryInPHP.php?upload=success");


            }
          }
        }
      } else {
        echo "File Size is way to big";
        exit();
      }
    } else {
      echo "You had an error with the file";
      exit();
    }
  } else {
    echo "The file type you tried to upload is not allowed!";
    exit();
  }
}
?>

I expect the file to upload without problems. 我希望文件上传没有问题。 It seems I am overlooking something rather simple. 看来我忽略了一些简单的事情。

Hint: There are 3 files connected to this one. 提示:有3个文件与此文件相关。 1. The gallery.php where the form exists for images to be uploaded 2. The one which is pasted here 3. the DB handler file 1. gallery.php,其中存在要上传图像的表单2.将其粘贴到此处3. DB处理程序文件

',其中一个文件处理程序文件出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM