-1

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..

User
  • 360
  • 3
  • 4
  • 18
  • 3
    Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! – NullPoiиteя Mar 18 '13 at 07:09
  • @ashiq can you show your code ? – rusly Mar 18 '13 at 07:12

2 Answers2

1

"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.

Prasanth Bendra
  • 31,145
  • 9
  • 53
  • 73
1

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
}
Sudip Pal
  • 2,041
  • 1
  • 13
  • 16