Home > Uncategorized > Upload image Using PHP and store name into MySQL Database

Upload image Using PHP and store name into MySQL Database

Here I will show you how to upload the image using PHP . and  store that image into Specific folder and store the name of image intp Mysql database as well 

Before Start you need to create a database in your MySql Database . and you need to configure

1) Create a HTML Form and Copy this Code

<form method=”post” action=”addMember.php” >

Please Upload a Photo of the Member in gif or jpeg format. The file name should be named after the Members name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb.
<input type=”hidden” name=”size” value=”350000″>
<input type=”file” name=”photo”>

<input TYPE=”submit” name=”upload” title=”Add data to the Database” value=”Add Member”/>

2) You need to create another file = addMember.php and then copy below code


//This is the directory where images will be saved
$target = “your directory”;
$target = $target . basename( $_FILES[‘photo’][‘name’]);


// Connects to your Database
mysql_connect(“yourhost”, “username”, “password”) or die(mysql_error()) ;
mysql_select_db(“dbName”) or die(mysql_error()) ;

//Writes the information to the database
mysql_query(“INSERT INTO tableName (photo)
VALUES (‘$pic’)”) ;

//Writes the photo to the server
if(move_uploaded_file($_FILES[‘photo’][‘tmp_name’], $target))

//Tells you if its all ok
echo “The file “. basename( $_FILES[‘uploadedfile’][‘name’]). ” has been uploaded, and your information has been added to the directory”;
else {

//Gives and error if its not
echo “Sorry, there was a problem uploading your file.”;


Categories: Uncategorized
  1. varun
    November 28, 2012 at 5:35 am

    Hey Rushikesh
    you need to mention multipart/formdata in the form first then only can the uploaded data be sent.

    • Raj
      June 29, 2013 at 11:37 am

      Hi Varun,
      Can you please upload the correct coding with your changes?

  2. King Musa
    December 29, 2012 at 9:16 am

    Thanks man it working but it does not save in the right target

  3. paul
    May 7, 2013 at 4:45 pm

    i do not understand the database part . i will create a database then a table called? With what attributes?

    • paul
      May 7, 2013 at 4:47 pm

      someone help. eagerly waiting

  4. June 18, 2013 at 6:46 pm

    利用可能に3色相: 黒/製品、チョコレート/クリームと海軍/製品。背の高いバッグもありますかなり2 つインスタンスほど背が高く。彼ら 到着 では 様々
    の 色 とすることができます 両方 にスリップまたはレースを モデル バッグします。
    フリップフ ロップは 夏 多年生のお気に入り。

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: