Upload Image In PHP With MySQL Database

Upload Image In PHP, With MySQL Database: Nowadays we are on social networks, and we upload DP Stories etc. Ever wondered how this photo is uploaded in the database. After that, we can see images which are coming out of the database. So, Today we will learn how to upload image in database using PHP & MySQL.  Basically, In this tutorial, we will create a form with two inputs. First, for image upload, the second one is to write some text with an image. When someone selects an image write some text & click on the upload button, the image name and text will be upload in MySQL database. And PHP grabs image file and save it in a folder. 

Upload Image In PHP Tutorial

Firstly,  Create a MySQL database named “image_upload” & create a table named “images”.  You can give a custom name for database and tables but, then you have to changes database & table name in PHP file too.  If you have good knowledge in PHP then it’s ok Otherwise, just follow my steps.

Create a database named “image_upload” & click on the database you have created now. Then go to SQL menu and paste these code & click on go.

Now you have successfully created a database for this program. Now Create a file named “index.php” & a folder named “images” in the same destination where you saved index.php file. Now let me explain some important things about this program: I had created a form with method=”POST” and put on action index.php (action=”index.php”) file. You can create another file for PHP I had put everything in a single file.

Note: Make sure you put enctype=”multipart/form-data” in form. Example ( <form method=”POST” action=”index.php” enctype=”multipart/form-data”> ), And don’t forget to create “images” folder. Otherwise, this program will not work.

Source Code

Open “index.php” file you had created before and paste these codes give below:

That’s It. Now you have successfully created image upload in PHP & MySQL program. This a very basic program, I created this for those people who are beginners and want to learn. In the future, I will share advance PHP programs also. If You have any question or doubt comment down below.

Share on:

Hello, I am Dharmendra Yadav and I am a Python Developer with experience in web development using Django, Flask, REST API, SQL, MySQL, HTML, CSS, JavaScript, WordPress, Oracle Cloud, AWS and Git. I also write technical articles where I explain web development and Software Engineering. Facebook , Linkedin

Leave a Comment