php - Get an blank image after updating the form detail
Get the solution ↓↓↓Solution:
You have to put this condition
$Subcategory_image ="";
if($Subcategory_id){
$sql = $d->select("sub_categories", "Subcategory_id="$Subcategory_id);
if($sql->num_rows>0){
$data=mysqli_fetch_array($sql);
$Subcategory_image = $data["Subcategory_image"];
}
}
$check = getimagesize($_FILES["Subcategory_image"]["tmp_name"]);
if($check!=false){
move_uploaded_file($_FILES['Subcategory_image']['tmp_name'], 'images/categories/' . $_FILES['Subcategory_image']['name']);
$Subcategory_image = $_FILES['Subcategory_image']['name'];
$m->set_data('Subcategory_image', $Subcategory_image);
}
$m->set_data('Category_id', $Category_id);
$m->set_data('Subcategory_description', $Subcategory_description);
$m->set_data('Subcategory_name', $Subcategory_name);
also assign existing image to $Subcategory_image before this condition so that if file control is empty it get old image else of making old image field empty in db table
Answer
Solution:
Yeah this is because the image input is taking as null as uploading it to database .. add a additional condition as when there is no image input assign the previous image input to the variable
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: npm err! code 1
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.