I watched a tutorial on how to do this and still cannot get the image to upload to mysql as a blob.
I want to allow the user to select an image.
<form action="includes/submitImage.inc.php" method="POST" enctype="multipart/form-data">
<input type="file" name="image1">
<button type="submit" name="submit">Save Image</button>
</form
On submit, it should send this image to mysql db and save it as a blob. db field name is 'selectedImage'.
Contents of submitImage.inc.php:
<?php
include_once 'dbh.inc.php';
$imageData1 = mysqli_real_escape_string(file_get_contents($_FILES['image1']['tmp_name']));
$imageType1 = mysqli_real_escape_string($_FILES['image1']['type']);
$sql = "UPDATE myDbTable SET selectedImage='$imageData1' WHERE id='1';";
mysqli_query($conn, $sql);
header("Location: ../home?edit=success");
exit();
?>
This has been watered down to simplify the question. Checks were made that a row with id=1 exists. Code completely makes it through all conditions and url contains 'home?edit=success' as expected. All other fields (that aren't included here) update their values as expected, but the record shows '[BLOB - 0 Bytes]' under the selectedImage field.
Any ideas? I've omitted any code not pertaining to the image and also have changed field names for simplicity. Your time and help are greatly appreciated.