The connection process is very easy in PHP MYSQLi. The PHP mysqli plugin helps to use the readymade function to create a connection string using PHP MySQLi. We can connect HTML page usng PHP connect function. You cannot connect HTML without PHP programming and the MYSQL database. Here, We will connect the MYSQL database using PHP MySQLi . I would like to suggest understanding the MYSQL database. MYSQL is used to create a database structure.
How to connect MYSQL database using PHP mysqli ?
The HTML page can be connected with the database using PHP mysqli and MYSQL queries.
Step 1- First of all install the xampp and wamp server on your computer. Xampp and wamp are local servers. Here we will use xampp server to connect a simple HTML web page to the database.

Download and install the xampp server on your computer. You can check the complete reference for xampp local server configuration.
How to download and Install Xampp local sever?
Step 2- In this step, you have to create a database on localhost/phpmyadmin/ PHP admin panel and create a table inside the database name.
I. Create a new database.
II. Create a table inside the database.
To connect the HTML page to the MYSQ database using PHP mysqli , you have to create a table. You can create an MYSQL table manually or use the query below.
Create a table using the query below-
CREATE TABLE `user` (
`id` INT( 40 ) NOT NULL ,
`uname` VARCHAR( 30 ) NOT NULL ,
`upassword` VARCHAR( 40 ) NOT NULL
) ENGINE = INNODB DEFAULT CHARSET = latin1;
Step 3- We will use an HTML form to connect the database using PHP. Here we will create a simple login form in HTML To connect the HTML form to the database, we insert some data in the database table. You can use the signUp system to create a new user or insert it manually using the query.
INSERT INTO `user`(`id`, `uname`, `upassword`) VALUES (1,'admin','admin@123');
UserName=admin
Password = admin@123
Step 4- Now, create an HTML form. We will connect the HTML form to the database using a PHP mysqli .
<form action="" method="POST">
<b>Username:-</b><input type="text" name="uname" required=""><br><br>
<b>Password:-</b><input type="text" name="upassword" required=""><br><br>
<input type="submit" name="sub" value="Login">
<form>
Step 5- Now create a connection file. A connection file writes in the PHP script. This connection file is used to connect the HTML page to the MYSQL database.
Create a connection file and save it as - config.php
<?php
$databaseHost = '127.0.0.1';//or localhost
$databaseName = 'test'; // your db_name
$databaseUsername = 'root'; // root by default for localhost
$databasePassword = ''; // by defualt empty for localhost
$mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName);
?>
If you are using an object-oriented style then you create MYSQLI connection like this -
<?php
$mysqli = new mysqli("localhost","username","password","database");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
?>
Step 6- Now create PHP script to connect HTML pages .
In the PHP script, we use many pre-defined functions. These functions are known as built-in functions in PHP.
<?php
include("config.php");
if(isset($_POST['sub']))
{
$uname = $_POST['uname'];
$upassword = $_POST['upassword'];
$res = mysqli_query($mysqli,"select* from user where uname='$uname'and upassword='$upassword'");
$result=mysqli_fetch_array($res);
if($result)
{
echo "You are login Successfully ";
//header("location:my-account.php"); // create my-account.php page for redirection
}
else
{
echo "failed ";
}
}
?>
Now, you can log in. In this way, you can connect the MYSQL database using PHP mysqli .
References -
Registration and login form in PHP and MYSQL
CRUD application in PHP