
Step 4 : Store Image in Database using PHP We have used "mysql_connect()" function to connect mysql and "mysql_select_db()" function to connect to particular database. We will create a new php file for the connection and lets name it as "mysqlconnect.php". Primary Key, " images_path" to save image path and " submission_date" to note the image uploaded date. If you want you can use "phpmyadmin" an interface to create tables or database.Īs you see from above the screen shot that we have successfully created a table called " images_tbl" with columns " images_id" as To create a database table, we need to write a mysql query. Since we will be using PHP scripting language to save an image to the server therefore in the " form-action" attribute we will use file with ".php" extension. So while uploading any image file make sure you have set those above attributes properly.

These attributes is available in " form" tag. To upload any image file, It is mandatory to set following attribute as, enctype = "multipart/form-data" and action="a target path where form-data will be posted" before submitting it to the server and this is only applicable in HTTP method = "post". In step 1, let's create a simple HTML form.Īs you see from our above code that we have created a simple form which consist of input:file and input:submit button. In this article, step by step we will see php code example to how to upload an image and store that uploaded image path in mysql database using PHP code.
