Good morning, I have a problem uploading an image to my database. I have several different data and all are saved except the image, which I configured with the column name "IMG" and longblob file type
This is my HTML:
<div class="control-group">
<div class="form-group floating-label-form-group controls">
<label>Fotos del platillo</label>
<input type="file" name="IMG" class="form-control" placeholder="Fotos del platillo" id="IMG" required data-validation-required-message="Debes rellenar este espacio.">
<p class="help-block text-danger"></p>
</div>
</div>
This is the function of ajax within the same HTML
<script>
$(document).ready(function () {
$("#boton2").click(function () {
var DATE = $("#DATE").val();
var NAME = $("#NAME").val();
var DESCR = $("#DESCR").val();
var IMG = $("#IMG").val();
var COSTO = $("#COSTO").val();
$.post("saveFitGreenMenu.php", {
DATE: DATE,
NAME: NAME,
DESCR: DESCR,
IMG: IMG,
COSTO: COSTO
},
function (data, status) {
console.log(data);
});
});
});
</script>
This is all I have in the php to save
<?php
include "conexionFitGreen.php";
if(mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}else{
$DATE = $_POST["DATE"];
$NAME = $_POST["NAME"];
$DESCR = $_POST["DESCR"];
$IMG = $_FILES["IMG"];
$COSTO = $_POST["COSTO"];
if($con){
//Paso 2
$sentencia = $con->prepare("
insert into menudia(DATE, NAME, DESCR, IMG, COSTO)
values(?, ?, ?, ?, ?)");
//Paso 3
$sentencia->bind_param("sssbi", $DATE, $NAME, $DESCR, $IMG, $COSTO);
//Paso 4
if($sentencia->execute()){
//echo "Datos del paciente guardados exitosamente!";
}
$sentencia = $con->prepare("select * from menudia");
if($sentencia->execute()){
$sentencia->bind_result($DATE, $NAME, $DESCR, $IMG, $COSTO, $ID);
}
}
}
?>
I hope you can help me. I know that everything is fine since the other parameters keep them without problems, but the image always goes blank in the database. Thank you very much in advance.