PHP MySql insert into

PHP MySql insert into tutorial will explain you How to insert data in database table in PHP with Examples. When data is put into a MySQL table it is referred to as inserting data. When inserting data it is important to remember the exact names and types of the table’s columns.

Syntax for PHP MySql insert into

MySql insert into syntax that we will use comes in two forms –

  • without column names and
  • with column names

Form 1:

Form 2:

Example on PHP MySql insert into

To insert data into table example(id, name, age), where id field is a primary key and auto incremented.

Insert data from form into database

For inserting data from form, we need HTML form and PHP code to receive the data from HTML form.

Here is Example on PHP MySQL insert into from HTML form

So first we create HTML form:
Html file html_form.html

This HTML form will send two variables, name and address, to input.php file as described in the ACTION parameter of FORM

Here is the code of input.php

In above example, when user insert some data in HTML form and click on submit button, form data is sent to the input.php.

The input.php file retrieves values from HTML form with the help of $_POST variables and performs connection with database.

mysql_query() function will execute insert statement and after successful execution data will be inserted into table data_employees.

SHARE
Previous articlePHP MySql Create database and tables
Next articlePHP MySql Select Query
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!