I want to upload an image into database using PHP. I get the following error when trying to upload:
Error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
dbname:img
tablename:image
column:img
type:LongBLob.
I've already managed to connect to the database before and was able to insert anything except image contents. Here is my code:
<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<button>Go</button>
</form>
<?php
$C = new mysqli("localhost","root","","img");
if(!$C->error) {
echo "Connected";
} else {
echo $C->error;
}
if(isset($_FILES['file'])) {
$F = file_get_contents($_FILES['file']['tmp_name']);
$Q = "insert into image (img) values('$F')";
$R = $C->query($Q);
if($R == true) {
echo "ok";
} else {
echo $C->error;
}
}
?>