How to display current image name from database in file field when editing in php? [closed]

StackOverflow https://stackoverflow.com/questions/15471389

  •  24-03-2022
  •  | 
  •  

Question

I am using a file field in my webpage,my problem is when i clicking edit option in my webpage i want to show the current image name from database in the file field,now i cant show the image name so when clicking edit file field become blank and after updating database also become blank. So every time i have to select the image,before updating.

How to solve this problem please help me Is it possible to set a value for file field?

Thanks in Advance..

Was it helpful?

Solution

"i want to show the current image name in the file field" => You can not Do that.

Best option would be :

While editing the data check for your file field,

if the file field is empty (user don't want to change the image), Don't update the image field in data base let it be what was it before, so it will not be blank.

if(!empty($_FILES["your_file_field_name"]["name"])){
    // update database field for image
    // Update other fields
}else{
    // Update other fields
}

To make it user friendly : Just show the current image near the file filed in your form, So that user knows current image.

OTHER TIPS

The problem may have a different solution..

Try to add a if-else block for file field, when the file field is empty then you should not update the file field in the database or vice versa

if(!empty($_FILES["img"]["name"])){
// write to dB
}else{
// not
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top