how to upload image in php and store in database and folder?

In this image upload in php code with databases article, i make a HTML form that takes user profile an image as well as some users bio text. When the user selects any your profile an image and enters some Bio text and then simply clicks the submit button, the all the users data is submitted to the server side and save MySQL Database. PHP now grabs the image as well as saves it in a folder in the main upload project, and then saves the text in the mysql database together with a link pointing to the image in the profiles folder.

How to Upload Image into Database and Display it using PHP ?

Create a database called users_master and make a mysql table called users profiles with some added fields like as image type, file name, size or many more:

Also Read: Multiple Image Upload using PHP into MYSQL database

  • id – int(11)
  • image – varchar(255)
  • file_imag_name – text

Make a file called profile.php and page the following code in it (the complete code):

profile.php:

  • Make database connection
  • Initialize message variable
  • If upload button is clicked
  • Get image name
  • Get text
  • image file directory
  • execute query




Image Upload



"; echo "image upload in php code with databases"; echo "

".$row['file_imag_name']."

"; echo "
"; } ?>

And that’s all.

Also Read: PHP Simple Image Upload and Display Source Code

Be sure to HTML Form include the enctype in your HTML form tag. such as bellow Example:

Without the HTML attribute FORM enctype=”multipart/form-data”, the image or file won’t be uploaded. so must added the enctype is the encoding type that specifies format how the HTML form-data should be encoded when yout profile submitting the HTML form. Without it file or images uploads won’t work.

Leave a Comment