Insert html form Data to mysqli Database using PHP: Friends, in the previous article, we learned how to create a table in a database? Before reading this article, you must read the previous article once, then today’s topic will help you to understand. We already know that when a website has a profile system, a registration form is required. With all the data in this registration form that the form is submitted, All that data is stored in the table.
Through today’s article we will know, How to save HTML form data in a database table using PHP coding. And we can use this data at a later time as needed. Database user data can be used in different ways in different places in a profile system.
Also read: Insert data from HTML form to Database using PHP mysqli
For example, we can display user all biodata the username in the username space of the profile. We can again display the mobile number, email id, address in the specified place of the user’s account. The user bio data needs to display some things in his profile so that the user can see that this account is his own.
Friends, we will not create any profile system for this article. Here we only show how HTML data can be saved in a database with PHP code.
The required files are
Friends, we need two files to do this. One file is “.html” file and the other is “.php” file. I hope you remember that, how to create different types of files in live web hosting server and Where we create different types of files.
And with that we need databases and database table. We have to go to the previous article and create a database table. If you haven’t read the previous article, you must read it once to understand this.
Insert html form Data to mysqli Database using PHP
We need an html file. Here, for example, I named the html file “index.html” – Why index.html file is so important for a website? The reason I have taken the index.html file here is because we learned in a previous article that the index.html file is the default page of a website, that is, when a website is opened in a browser, this page opens first.
We need an php file. Here, for example, I named the html file “process.php” – Here I have taken a file named process.php. In this fill we will do all the coding where and how to save all the data from html form.
To do all this we need to login to our live web hosting server. That means you have to login to cPanel. We have already learned in previous articles how to login to cPanel.
#1 Create HTML form (index.html)
After logging in to cPanel, open the public_html folder and create a file named index.html in it. Follow the process below-
After login in to cPanel -> Click file manager -> Click public_html -> Click on +File from menu bar -> Enter file name (index.html) -> Click Create New File.
New file index.html Create Process
<!DOCTYPE html>
<html>
<body>
<h2>Registration Form</h2>
<form action="process.php" method='POST'>
Name: <input type="text" name="name"> <br><br>
Mobile No:<input type="text" name="mobileno"> <br><br>
Email: <input type="text" name="email"> <br><br>
Address: <input type="text" name="Address"> <br><br>
<input type="submit" name='submit' value="Submit">
</form>
</body>
</html>
Friends, we have learned about almost all the issues of this basic HTML form in the previous article. Here only we will know about the <form> </form> tag. This tag is used to add all kinds of input boxes to this tag.
- form action=”” – This means that this form is being attached to a file or a page. For Example – Here we have taken a .php file to process all the data and that file is called process.php so here the form is attached to the process.php file.
- form method=”” – This means, Which method will we use to store the data in My School database? As you can see, I will save the database using the post method here. There is also another method called GET method which we will discuss in another article.
Save the index file by copying and pasting these codes into the index file or manually typing these codes. Let’s run the page once and see if the page is working properly.
Run like – https://www.yourwebsite.com or http://www.yourwebsite.com or https://yourwebsite.com or http://yourwebsite.com
How to run website in web browser

#2 Create php file (process.php)
Open the public_html folder and create a file named process.php in it. Follow the process below-
Click public_html -> Click on +File from menu bar -> Enter file name (process.php) -> Click Create New File.
New file process.php Create Process
<?php
$servername = "localhost";
$username = "blog_root";
$password = "XXXXXXXXXXX";
$dbname = "merabiox_test_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
echo "Database connection 100% successful. Database connected.";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
Copy-paste the code into process.php or save by typing manually. Using this code we have linked our PHP page to the database. Let’s run the page once and see if the page is connected to the database.
To run this process.php file, enter your website’s domain name in the browser’s address bar and then add backslash process.php. Below is an example of this step –
https://www.yourwebsite.com or http://www.yourwebsite.com or https://yourwebsite.com or http://yourwebsite.com
** Select any one like – (https://www.yourwebsite.com/process.php) then Enter
How to run process.php file or page in web browser

Now this code is the main code to save the data from our HTML file to the database. This code will save or store data in our database table.
<?php
$name = $_POST['name'];
$mobileno = $_POST['mobileno'];
$email = $_POST['email'];
$address = $_POST['address'];
$sql = "INSERT INTO test_table (`id`,`name`,`mobileno`,`email`,`addess`) VALUES ('0','$name','$mobileno','$email','$addess')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
$received data variable name = $_POST[‘input box name’]; – Since we are using the POST method, post the dollar sign here and then the name of the input field should be given in this third bracket. Like – $name = $_POST[‘name’]; (<input type=”text” name=”name”>We learned in previous articles why we add name to input field boxes. In the PHP file you have to specify which input field is coming from which date. For this reason, the name of the input field of the HTML form has to be specified)
Also read: Send Email using php from html Contact Page – Website Design Step 5
$sql =” “ – INSERT {Here we are instructing SQL to insert data, that is, to add data to the table.} INTO test_table {We are specifying to SQL which table to add data to} (`id`,`name`,`mobileno`,`email`,`addess`) {To SQL we are specifying the names of all the columns in the table} VALUES (‘0′,’$name’,’$mobileno’,’$email’,’$addess’) {Here we are telling SQL which date to store in which cell in each column of the table.}
Full final code process.php
Copy this whole code and paste and save it in process.php file. Now we will enter our domain name in the web browser, run it once and check if the complete code is working properly.
<?php
$servername = "localhost";
$username = "blog_root";
$password = "XXXXXXXXXXX";
$dbname = "merabiox_test_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
echo "Database connection 100% successful. Database connected.";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = $_POST['name'];
$mobileno = $_POST['mobileno'];
$email = $_POST['email'];
$address = $_POST['address'];
$sql = "INSERT INTO test_table (`id`,`name`,`mobileno`,`email`,`addess`) VALUES ('0','$name','$mobileno','$email','$addess')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
After visiting the website Iran, we will be able to see the results after submitting all the details in the registration form. If our result is New record created successfully then we understand that our submitted data has been successfully saved in the database. Insert html form Data to mysqli Database using PHP.
Open your web browser -> enter your full domain -> Enter enter ( like – https://www.yourwebsite.com/ )
Now enter all details and submit

You can check the database login to see if the data is saved properly in the database. In the previous articles we discussed how to login to the database.
The last few words
Friends, I have already said that it is not possible to say all the things together through one article. We will gradually learn more about how to make this registration form more advanced in the following articles. I hope you enjoyed today’s article. Please share this article with your friends and family.
If you have any problem with this ID card or have any problem with this issue please let us know in the comment box and we will try to resolve your comment as soon as possible. If you need a complete website, be sure to contact us via email. We will try to complete your entire website as soon as we can.