How To Upload Image in PHP MySQL Database and Display in HTML

30 June, 2019 Hozaifa Sheikh 484 Views
How To Upload Image in PHP MySQL Database and Display in HTML

If you are beginner and want to learn How to Upload Image in PHP MySQL database and display in HTML then this article will really will help to upload image in PHP and Mysql, beginners always worry about How to upload different format of image in PHP and how to display image on front end, So don’t worry I am going to share a simple method that will help you to Upload Image in PHP MySQL database and display in HTML.

Note: I am using MySQL to perform upload image in PHP and MySQL, so if you are using an old version of PHP, please upgrade into a newer version of PHP and MySQL.

Step by step Guide to How to Upload Image in PHP MySQL database and display in HTML

Create a Database 

  1. Open PHPMyAdmin
  2. Create a database   as “tutorial”
  3. Click create a table and name it as “user”

you can create a table through entering these line of code

Create an HTML Form To Upload Image

Create a file index.php and create a simple form to Upload Image in PHP MySQL database, whenever we upload image we always remember to add the following attribute into the form  enctype=”multipart/form-data”, this is  very important while upload files, every beginner make this mistake, and uploading image not work till they add.

Make a Connection with Database

Now we need to create one more file config.php where we will write a piece of code that will help to create a connection with the database.

Note: if you have not created a password for the database, the default password will be null.

Create Upload action file to Store Image in Database using PHP

To store uploaded image path in the database we will create a new PHP file name it as “image_upload.php” because in the “form” tag we gave “action” attribute target path as “image_upload.php” and in this file (“image_upload.php”) all the form-data will be posted.

Now time to come How to display image in HTML.

How to Display image from MySQL Database 

You can set the path to  show image like src=”upload/img/<?php echo $row[‘image’]; ?>”


About author

Hozaifa Sheikh

I am a professional blogger from my heart, I am going through all the possible ways that can help to audience. I am trying my best to write content that my readers will like me. I will really be happy when my readers will become more happy with my blog.

You may also like

Leave a Reply

Notify of
Scroll to Top
Share via
Copy link
Powered by Social Snap