簡體   English   中英

為什么要添加兩次 sql 插件?

[英]Why add sql insert twice?

上傳圖像並將 url 添加到數據庫表的代碼。 但是為什么要在 sql 表中添加兩行呢? 感謝幫助。

  if (in_array($fileActualExt, $allowed)) {
    if ($fileError === 0) {

      if ($fileSize < 30000000) {
        $fileNameNew = uniqid('', true).".".$fileActualExt;
        $fileDestination = $destination.$fileNameNew;
        $fileDestinationDB = $destinationDB.$fileNameNew;
        $move = move_uploaded_file($fileTmpName, $fileDestination);

        if ($move) {
          $sql = "INSERT INTO $dbTable (header_text, banner_title, images_url)
                  value ('$header_text', '$banner_title', '$fileDestinationDB')";
          $result = mysqli_query($connect, $sql);

          if ($connect->query($sql) === true) {
            header("Location: index.php?uploadsuccess");
          }
          else {
            unlink($fileDestination);
            echo "Error: ".$sql."<br/>".$connect->error;
          }
        }
      }
      else {
        echo "Filen är för stor";
      }
    }

替換這個:

if ($connect->query($sql) === true) {
        header("Location: index.php?uploadsuccess");
}

有了這個:

if ($result === true) {
        header("Location: index.php?uploadsuccess");
}

請檢查以下代碼,

 $result = mysqli_query($connect, $sql);

 if ($connect->query($sql) === true) {
    header("Location: index.php?uploadsuccess");
 }

您已經執行了兩次 mysql 查詢,請像這樣更改 if 語句,

if ($result) {
    header("Location: index.php?uploadsuccess");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM