Im not sure if you need to do it by Ajax or is it ok to refresh the site.
Here is an example for refreshing:
First of all you need a Formular (html):
<?php include("loginFunktion.php"); ?>
<form action="" method="Post">
<input name="name">
<input type="submit" name="test" value="test">
</form>
Thats the basic of your DB Class (new sheet):
<?php
class DB {
protected $mysqli;
function __construct(){
$this->host = "***";
$this->username = "***";
$this->database = "***";
$this->password = "***";
}
function connect(){
$this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s<br/>", mysqli_connect_error());
exit();
}
}
function disconnect() {
// Verbindung beenden
$this->mysqli->close();
}
}
?>
Now you have in include the class and connect to your DB by the constructor of your class (the following code is the loginFunktion.php sheet):
<?php
include("dbclassname.php");
$_DB = new DBData();
$_DB -> connect();
?>
Now you have a connection to your DB and u can do querys:
if(isset($_POST["test"])){
$queryCALL ="SELECT user FROM t_user WHERE user_name=".$_REQUEST["name"];
$result = $this->mysqli->query($queryCALL);
$ergebnis=$result->fetch_array()[0];
if(count($ergebnis)>0)
echo "this name is used";
}
If you are new on php ajax is a little bit to complicate for you. Nethertheless thats a good guide:
https://www.w3schools.com/php/php_ajax_database.asp
Next time please add more informations.