为什么我的图片无法添加到数据库中,即使我创建了一个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 :(得分:-2)
你已经检查过$ _POST ['picture']有数据了吗?
$ _ FILE保存有关附件的数据