If I try to submit an image, the echo works. So i'll see "it works". But when I check my db, it is not inserted. userId is a INT and foreign key to the id in another table and image is a BLOB.
code:
$userId = $_SESSION['id'];
if(isset($_POST['submit'])){
$imgName = $_FILES['image']['name'];
$imgData = $_FILES['image']['tmp_name'];
$getImgData = file_get_contents($imgData);
$imgType = $_FILES['image']['type'];
if(substr($imgType, 0,5) == "image"){
$query = "INSERT INTO projects (userId, image)
VALUES ('$userId', '$getImgData')";
$result = $db->query($query);
echo "it works!";
} else{
echo "only images are allowed";
}
}
?>
The echo works, but it won't insert. Please help with this, I've been stuck for hours now!
why insert the image in the db, just get the img path (upload folder) or name and insert it, in your code you can show your image by referencing it's path, except if you must insert it as blob you can refer to this posts