In this article, we are going to store data in database which is submitted through HTML form.
HTML form: First we create an HTML form that need to take user input from keyboard. HTML form is a document which stores information of a user on a web server using interactive controls. An HTML form contains different kind of information such as username, password, contact number, email id etc.
The elements that are used in an HTML form are check box, input box, radio buttons, submit buttons etc. With the help of these elements, the information of an user is submitted on the web server. The form tag is used to create an HTML form.
<form> Form Elements... </form>
To pass the values to next page, we use the page name with the following syntax. We can use either GET or POST method to sent data to server.
<form action=other_page.php method= POST/GET> Form Elements... </form>
Database Connection: The collection of related data is called a database. XAMPP stands for cross-platform, Apache, MySQL, PHP, and Perl. It is among the simple light-weight local servers for website development. In PHP, we can connect to database using localhost XAMPP web server.
How to get form data: We are going to collect the form data submitted through HTML form. PHP $_REQUEST method is a PHP super global variable which is used to collect data after submitting the HTML form.
Complete Steps to Design Project:
- Start XAMPP Server.
- Open localhost/phpmyadmin in your web browser.
- Create database of name staff and table of name college.
- Write HTML and PHP code in your Notepad in a perticular folder.
- Submit data through HTML Form.
- Verify the results.
Steps In detail:
- Start XAMPP Server by opening XAMPP and click on XAMPP Start.
- Open localhost/phpmyadmin in your web browser and create database with database name as staff and click on create.
- Then create table name college.
- Enter columns and click on save
- Now open Notepad and start writing PHP code and save it as index.php and open other notepad and save it as insert.php Save both files in one folder under htdocs.
Output: Type localhost/7058/index.php in your browser, it will display the form. After submitting the form, the form data is submitted into database.
Let’s check in our database