How to Upload Image into Database and Display it using PHP? and How to store it in the folder?

welcome all viewers thanks for reading and learning by now I explain how to insert an image file in your database. and how this insert file in-store your folder.

now start how to insert an image in PHP ( how to insert an image in the database ).

first your localserver on then open localhost/phpMyAdmin in your browser now create a new database and create a new table.

  1. Create new Database
  2. Create new table
  3. Create index.php file
  4. Create connection.php file
  5. Create a new Image store Folder

1.Create new Database

create new database in phpmyadmin . database name is uploadimage

2.Create new table

create new table in uploadimage database. table name is info

3.Create index.php file

now create index.php and write HTML structure then add PHP code also.

<!DOCTYPE html>
	<title>img </title>

	<form action="index.php" method="post"  enctype="multipart/form-data">
		<input type="file" name="pic"><br><br>
		<textarea rows="2" cols="100" name="comment" placeholder="enter comment"></textarea>
		<input type="submit" name="submit">

include 'connection.php';
if (isset($_POST['submit'])) {


	$sql="insert into info values('$id','$folder','$comment')";
	if ($con) {
		echo "insert";
		echo "error";
include 'connection.php';
$q1="select * from info";

if ($res=mysqli_num_rows($data)) {
	?><table border="2">
	while ($result=mysqli_fetch_array($data)) {
		echo "
		<td><img src='".$result['pic']."' width='350px'</td>


4.Create connection.php file

now this is connection.php file add here.


// Enter your Host, username, password, database below.
// I left password empty because i do not set password on localhost.
$connect=mysqli_connect('localhost','root','','uploadimage') or die("connection failed : ".mysqli_connect_error());

if ($connect) {
	// echo "Connection Successfully";
	echo "Sorry Some Mistakes is";
// Check connection
if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();


5.Create a new Image store Folder

Now open where the index.php file Create a new folder named image.


How to image insert and view in one page?

this is also explained.
this tutorial blog is very easy so now so read this blog.

How to Upload Image into Database and Display it using PHP? and How to store it in the folder this tutorial zip file available.

Leave a Comment

Your email address will not be published. Required fields are marked *