I have a problem when uploading images to the server, only the images in the table should be updated if a checkbox is checked, otherwise save the previous value
the database only saves the name of the associated image
Form.html
<form name ="dormUpdate" class="form" method="post" action="update.php" align="center">
<div align="center"></div>
<div class="info" align="center">
<fieldset>
<p> Producto </p>
<label for="id"> <input id="id" value="<?php echo $id; ?>" type="hidden" name="id" />
<label for="imagen_chica"> <span>Imagen Chica: </span> <input id="imagen_chica" value="<?php echo 'No Change'; ?>" type="file" name="imagen_chica" /></label><br>
<label for="changed1"> <span>Cambiar: </span> <input id="changed1" type="checkbox" name="changed1" /></label><br>
<label for="imagen_grande"> <span>Imagen Grande:</span> <input id="imagen_grande" value="<?php echo 'No Change'; ?>" type="file" name="imagen_grande" /></label><br>
<label for="changed2"> <span>Cambiar: </span> <input id="changed2" type="checkbox" name="changed2" /></label><br>
</fieldset></form>
update.php
<?php
ini_set('display_errors',1);
require "funciones.php";
$ch1 = 0;
$ch2 = 0;
$img_ch = 'NOT SET';
$img_gr = 'NOT SET';
$con = conecta();
$id = $_REQUEST['id'];
$ch1 = $_REQUEST['changed1'];
$ch2 = $_REQUEST['changed2'];
$target_path = './fotos';
$img1path = $target_path . $_FILES['imagen_chica']['name'];
if(move_uploaded_file($_FILES['imagen_chica']['tmp_name'], $img1path))
{
$img_ch = $_FILES['imagen_chica']['name'];
}
$img2path = $target_path . $_FILES['imagen_grande']['name'];
if(move_uploaded_file($_FILES['imagen_grande']['tmp_name'], "$img2path"))
{
$img_gr = $_FILES['imagen_grande']['name'];
}
$res = mysqli_query($con,"SELECT * FROM productos WHERE id = $id;");
$row = mysqli_fetch_assoc($res) ;
$img_1orig = $row['imagen_chica'];
$img_2orig = $row['imagen_grande'];
if($ch1 != "on"){
$img_gr = $img_1orig;
}
if($ch2 != "on"){
$img_ch = $img_2orig;
}
$res = mysqli_query($con,
"UPDATE productos SET
imagen_chica = '$img_ch',
imagen_grande = '$img_gr'
WHERE id = $id;"
);
/////////////////////////////