MySQL Insert Data | How to Insert MYSQL Data in PHP Loop

MySQL Data Interting


To previous tutorials we have  learned how to  Create database and create table.Now it's time to create some tables inside the database that will actually hold the data. A table organizes the information into rows and columns.

Some rules to be followed while inserting the values into database.

  • The query of SQL must be enclosed inside PHP quotes.
  • If any string values persists in the SQL query, it should be given in quotes.
  • Quotes should not be given to numeric values.
  • NULL should not be in quotes.

The records are inserted as shown in below syntax:

INSERT INTO table_name (column1, column2, column3,...)

VALUES (value1, value2, value3,...)

Note: There is no need to specify the value for columns with AUTO_INCREMENT (eg: “id” column) or TIMESTAMP (eg: “birth_date” column), MySQL automatically adds the value.

Example (MySQLi Object-oriented) :

Output:

Example (MySQLi Procedural) :

output :

Example (PDO)

output :