-2
我是新來的PHP和MYSQL試圖學習和正在進行的項目。我正在關注個人資料照片上的代碼教程,我正在嘗試上傳由特定用戶ID上傳的多張照片。它可以很好地上傳到文件目標,但是我遇到的問題是將它存儲到數據庫中。MySQL插入到表中不插入
這裏是我的upload.php的
<?php
session_start();
//connection to database
include_once('dbh.inc.php');
$id = $_SESSION['u_id'];
if(isset($_POST['submit'])){
//getting the file
$file = $_FILES['file'];
//file info
$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 formats
$allowed = array('jpg','jpeg','png');
//check if the format uploaded is allowed
if(in_array($fileActualExt,$allowed)){
if($fileError===0){
if($fileSize < 1000000){
//setting up for a new file name
$fileNameNew = $id.".".$fileName.".".$fileActualExt;
$fileDestination = 'uploads/' . $fileNameNew;
move_uploaded_file($fileTmpName,$fileDestination);
//inserting into database
$sql = "INSERT INTO imageuploads (image,uid_fk) VALUES ('$fileNameNew','$id')";
mysqli_query($conn,$sql);
header("Location: ../artsy.php?uploadsuccess");
}else{
echo "This file is too large";
}
}else{
echo "There was an error uploading this file";
}
}else{
echo "You cannot upload files of this type";
}
}
的imageuploads數據庫包含「img_id」這是自動遞增,「圖像」,這是一個varchar將包含新的文件名,「uid_fk」,這是一個引用用戶標識的外鍵標識。
我沒有收到任何錯誤,但沒有創建新行,但是當我在SQL本地主機上運行它時,它很好,並創建了一個新行。
如果你沒有收到錯誤的可能是因爲你沒有添加一些錯誤檢查就像mysql錯誤返回後的查詢,可能是你沒有檢查日誌服務器我的意思是Apache日誌或MySQL日誌PHP日誌... – 2017-09-23 15:29:31