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.
You May Also Like
Build a Simple Quiz In PHP | Source Code
Domain Availability Checker In PHP | Get Source Code
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.
CREATE TABLE `images` (
`id` int(11) NOT NULL,
`image` varchar(100) NOT NULL,
`image_text` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
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. More info about PHP Method.
Note: Make sure you put enctype=”multipart/form-data” in form. Example (