How to insert data into database using HTML form

“How to insert data into database using HTML form” is locked How to insert data into database using HTML form

Hello, In this post we will learn about mysqli query to insert data into database using  HTML form. For this process we have to required 2 files, one is HTML file and another is php file. HTML file is used to create a HTML form and php file is used to define database connection or insert query.

Here i created a simple HTML form that have <input> text field and submit field to trigger insert query.

index.html

From above HTML form, when user fill the fields detail and click on submit button, the form data will passed to “insert.php” file. The ‘insert.php‘ file create the connection to MYSQL Database and retrieves form fields data using $_POST variable, after this trigger the insert query to add record. Below is the complete code of ‘insert.php‘ file.

insert.php

MYSQLi Procedural Interface

MYSQLi Object-oriented Interface

Related posts