In this code when I navigate to the update form I get all the details as per database but when I update the form without selecting the image file it shows blank in the table.
if (isset($_POST['update_sub_categories']))
{
$file = $_FILES['Subcategory_image']['tmp_name'];
this are the conditions for update images
if (file_exists($file))
{
$errors = array();
$maxsize = 2097152;
$acceptable = array(
'image/jpeg',
'image/jpg',
'image/gif',
'image/png'
);
if (($_FILES['Subcategory_image']['size'] >= $maxsize) || ($_FILES["Subcategory_image"]["size"] == 0))
{
$errors[] = 'File too large. File must be less than 2 megabytes.';
// code...
}
if (!in_array($_FILES['Subcategory_image']['type'], $acceptable) && (!empty($_FILES["Subcategory_image"]["type"])))
{
$errors[] = 'Invalid files type. Only JPG, GIF and PNG types are accepted';
}
}
Conditions end at this point if no errors are found, the file will be uploaded
if (count($errors) === 0)
{
move_uploaded_file($_FILES['Subcategory_image']['tmp_name'], 'images/categories/' . $_FILES['Subcategory_image']['name']);
$Subcategory_image = $_FILES['Subcategory_image']['name'];
// code...
$m->set_data('Category_id', $Category_id);
$m->set_data('Subcategory_description', $Subcategory_description);
$m->set_data('Subcategory_name', $Subcategory_name);
$m->set_data('Subcategory_image', $Subcategory_image);
$a = array(
'Category_id' => $m->get_data('Category_id') ,
'Subcategory_description' => $m->get_data('Subcategory_description') ,
'Subcategory_name' => $m->get_data('Subcategory_name') ,
'Subcategory_image' => $m->get_data('Subcategory_image') ,
);
$q = $d->update("sub_categories", $a, "Subcategory_id='$Subcategory_id'");
if ($q > 0)
{
header("location:Manage_subcategories.php");
}
else
{
echo "Error";
}
}
else
{
header("location:Manage_subcategories.php?msg=invalidfile");
}
}
So how can i solve this? When i click on the submit button without selecting any image files it shows blank at the table and it does not show the image that is already available