I am aware that this code is vulnerable for SQL injections, but I don't know how to avoid it.
<?php
session_start();
$message="";
if(count($_POST)>0) {
require ''.$_SERVER['SERVER_NAME'].'/admin/settings.php';
mysqli_connect($host, $user, $pass);
mysqli_select_db($db);
$username = mysqli_real_escape_string($_POST['user_name']);
$password = mysqli_real_escape_string($_POST['password']);
$result = mysqli_query("SELECT * FROM members WHERE username='" . $username . "' and password = '". $password."'");
$row = mysqli_fetch_array($result);
if(is_array($row)) {
$_SESSION["user_id"] = $row[id];
$_SESSION["user_name"] = $row[username];
} else {
$message = "Invalid Username or Password!";
}
}//End of if
if(isset($_SESSION["user_id"])) {
header("Location:dashboard.php");
}
?>