无法将图片添加到数据库

时间:2017-10-10 11:09:14

标签: php

为什么我的图片无法添加到数据库中,即使我创建了一个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>

1 个答案:

答案 0 :(得分:-2)

你已经检查过$ _POST ['picture']有数据了吗?

$ _ FILE保存有关附件的数据