2017-10-08 175 views
1
<?php include"dbconn.php"; 
    if(isset($_POST["submit_image"])){ 
     $imgdate = $_POST["image_date"]; 
     $imgalbum = $_POST["image_album"]; 

$check = getimagesize($_FILES["image"]["tmp_name"]); 
    if($check != false){ 
     $image = $_FILES['image']['tmp_name']; 
     $imgContent = addslashes(file_get_contents($image)); 

    $insert = "INSERT INTO image_db (img_pic, img_date, img_album) VALUES ('$imgContent', '$imgdate', '$imgalbum')"; 
    $result = mysqli_query($conn,$insert); 
    //check if the row were updated 
    if (mysql_affected_rows($result)>0){ 
    echo "File uploaded successfully."; 
    }else{ 
    echo "File upload failed, please try again."; 
    } 
}else{ 
    echo "Please select an image file to upload.";}}?> 

頂部PHP文件我把它叫做upload.php的爲什麼上傳失敗PIC

底部一個我稱之爲upload.html

的形式將在upload.html那麼當用戶點擊它會重定向到upload.php的

我dbconn.php已經連接到表

<!DOCTYPE html> 
 
<head> 
 
\t <title>Upload picture</title> 
 
</head> 
 
<body> 
 
<form method="POST" action="upload.php" enctype="multipart/form-data"> 
 
\t <input type="file" name="image"> 
 
\t <label for="text">Image Date :</label> 
 
\t <input type="text" name="image_date"> 
 
\t \t <label for="text">Image Album:</label> 
 
\t \t <input type="text" name="image_album"> 
 

 
\t <input type="submit" name="submit_image" value="Upload"> 
 
</form> 
 
</body> 
 
</html>

我堅持在這裏和一直在說,我的mysql_affected_rows()函數預計參數1是資源,布爾給予 並保持沒有上傳

+0

你需要用mysqli的功能,沒有mysql mysqli_affected_rows並沒有mysql_affected_rows改變的條件。 – 2017-10-08 16:53:30

+0

問題是爲什麼你得到了錯誤mysql_affected_rows()...如果你因爲這個改變而得到了一個上傳錯誤,我得到的是與這個改變無關的,這個錯誤之後這個錯誤就出現了。因此關閉主題因爲使用了錯誤的mysqli函數,並且使用存儲錯誤的代碼部分的新錯誤執行了新主題,因此解決了此錯誤。問候。 – 2017-10-08 17:29:52

+0

我很抱歉花了很長時間回覆。我和我的朋友注意到了這個錯誤。我忘了寫聲明來調用/選擇數據庫/表.. tq這麼多的幫助,欣賞它.. –

回答

1

試試這個:mysqli_affected_rows沒有mysql_affected_rows

你需要使用前filter_input發送數據到MySQL服務器。 http://php.net/manual/en/function.filter-input.php

$insert = "INSERT INTO image_db (img_pic, img_date, img_album) VALUES ('" . $imgContent . "', '" . $imgdate ."', '" . $imgalbum . "')"; 
+0

tq幫助..我只是試過,但它仍然表示「 警告:mysql_affected_rows()期望參數1作爲資源,第19行C:\ xampp \ htdocs \ caseproject \ upload.php中的布爾值 文件上傳失敗,請重試。「 –

+0

@mohd fadzil請求之前做一個var_dump($ imgContent);和所有的參數,並檢查數據是否有效。 – 2017-10-08 16:45:26

+0

感謝您的新知識....我注意到,從我的img_date和我的img_album數據沒有插入數據庫,它顯示錯誤..是否有可能數據是高? –