How to Insert Value Into Database in PHP

This article explains how to insert value into a database in PHP.

Introduction

This article explains how to insert value into a database in PHP. The following methods are used:
· $_POST[]
Example

In this example, we implement the insertion of a value into a database in PHP. There are certain steps to follow as explained below.
Step 1

Create a database with the name demo as shown below.
Step 2

Now create a table named in_ch with fields in the table like name, address, city and contactnumber as shown below.
Step 3

Now create a file index.php in your text editor and save it inside the www folder (localhost) and write the following code as shown below.
Step 4

Now open the index.php file in your local server as shown below.
Step 5

Now fill in the form. Click on the submit button and it will show the confirmation message.

Output

Check the following values in the database: