Home > Software engineering >  How to upload image automatically if user wants to edit info PHP MySQL?
How to upload image automatically if user wants to edit info PHP MySQL?

Time:11-16

I have created a registration form which takes inputs username, email, password, and image. If user wants to edit his profile, I add all values in inputs and user can submit form again. But when he click on update button the image should be uploaded automatically and not empty. On my end it is empty. You can see in the image that user want to update Info but can't see the uploaded image. Other info was retrieved.

my front end screenshot:

my front end screenshot

I tried to show the image using src attribute but this isn't going to work. Please let me know how I can achieve this.

CodePudding user response:

A file input can only select from the local filesystem, so you can't pre-populate it with something from the server.

Use an <img tag to display existing images from the server.

For example, in your HTML form:

File:-
    <input type="file" name="image"><br><br>
    <input type="hidden" name="old_image" value="<?php echo $row['images'] ?>">
    <img src="<?php echo "files/images/".$row['images']; ?>">
  • Related