2017-10-10 53 views
-1

爲什麼我的圖片無法添加到數據庫中,即使我創建了blob數據類型來存儲變量$picture的文件?無法將圖片添加到數據庫

 //prepare and bind >> 
     $stmt = $conn->prepare("INSERT INTO user (name, email, gender, phonenum, address, ic_number, occupation, picture) VALUES 
        (?, ?, ?, ?, ?, ?, ?, ?)"); 
     $stmt->bind_param("sssssssb", $name, $email, $gender, $phonenum, $address, $ic_number, $occupation, $picture); 

      //    add into database >> 
     $name = $_POST['name']; 
     $email = $_POST['email']; 
     $gender = $_POST['gender']; 
     $phonenum = $_POST['phonenum']; 
     $address = $_POST['address']; 
     $ic_number = $_POST['ic_number']; 
     $occupation = $_POST['occupation']; 
     $picture = $_POST['picture']; 

     echo "New records created successfully"; 
     $stmt->execute(); 
     $stmt->close(); 
     $conn->close(); 
    } 
    ?> 

</div> 
<div class="right"> 
    <h3>Profile picture: </h3> 
    <img id="output" style="width:150px;height:200px;"/> 
    <br><input type="file" name="picture" placeholder="" onchange="loadFile(event)"> 


</div> 
<!--   pictures--> 
<script> 
    var loadFile = function (event) { 
     var output = document.getElementById('output'); 
     output.src = URL.createObjectURL(event.target.files[0]); 
    }; 
</script> 
+0

你爲什麼甚至在執行查詢之前,輸出「新記錄成功塑造了」成功信息數據?爲什麼你沒有做任何事情來檢查查詢是否真的成功,如果沒有被問到數據庫什麼錯誤 - 儘管如何做到這一點很容易研究/閱讀? – CBroe

+0

@Carey這是一個不真實的陳述。請閱讀手冊http://php.net/manual/en/mysqli-stmt.bind-param.php中的第一個示例,然後刪除您的評論。 – mickmackusa

回答

-2

你已經檢查過$ _POST ['picture']有數據嗎?

$ _FILE保存關於附加文件

+1

這應該是一個評論。 –