I would like to know how I can solve this inconviente. I am using class class.upload.php.
When editing a news, I want that if I do not select a new photo in the input file, I KEEP THE PHOTO SAVED (that is, the first one that came up when loading that news). I get the UPDATE correctly when I edit all the fields including the image of the news, but what does not come out is when I only edit the input, without adding a new image.
My code is this:
elseif ($accion == 'modificar') {
$idNoticia = $_POST['idNoticia'];
$imagenNoticia_guardada = $_POST['imagenNoticia-guardada'];
$tituloNoticia = $_POST['tituloNoticia'];
$noticiaCorta = $_POST['noticiaCorta'];
$noticiaCompleta = nl2br($_POST['noticiaCompleta']);
$imagenNoticia = new upload($_FILES['imagenNoticia']);
if (empty($imagenNoticia)) {
$imagenNoticia = $imagenNoticia_guardada;
}
if ($imagenNoticia->uploaded) {
$imagenNoticia->image_resize = true;
$imagenNoticia->image_ratio = true;
$imagenNoticia->image_x = 573; //ancho
$imagenNoticia->image_ratio_y = true; //alto de acuerdo al ancho, mantiene perspectiva.
$imagenNoticia->image_watermark = '../img/watermark.png';
$imagenNoticia->image_watermark_position = 'TL';
$imagenNoticia->process('../img/noticias/');
if ($imagenNoticia->processed) {
$statement = $conexion->prepare("UPDATE noticias SET tituloNoticia = :tituloNoticia, noticiaCorta = :noticiaCorta, noticiaCompleta = :noticiaCompleta, imagenNoticia = :imagenNoticia WHERE idNoticia = $idNoticia"
);
$statement->execute(array(
':tituloNoticia' => $tituloNoticia,
':noticiaCorta' => $noticiaCorta,
':noticiaCompleta' => $noticiaCompleta,
':imagenNoticia' => $imagenNoticia->file_dst_name
));
echo "La noticia ha sido editada correctamente.";
}
}
The problem in my opinion is in this line that something I'm doing wrong, or I'm assigning it wrong.
if (empty($imagenNoticia)) {
$imagenNoticia = $imagenNoticia_guardada;
}
He shows me NO MESSAGE OF ANYTHING. I even add an echo inside that if and it does not show it either.
I hope you can help me, thank you very much!