First you need to create a from with action="" and method="" attributes.
<form action="" method="">
</form>
Then create a php file named database.php in this file you need to add this code. Remember that don't forget to change this 'server_name', 'user_name', 'password', 'database_name' with yours.
// This changes are required
$mysqli = new mysqli('server_name', 'user_name', 'password', 'database_name') or die(mysqli_error($mysqli));
Then create a test table in your database
CREATE TABLE IF NOT EXISTS database_name (
id int() NOT NULL AUTO_INCREMENT,
task varchar(255) NOT NULL,
PRIMARY KEY (id)
);
then require the database.php file above the form
<?php require_once 'database.php'; ?>
then set the form action and method
<form action="database.php" method="POST">
</form>
Now your form is successfully connected to the database.