My php code is not processing the login verification and sticks to the login_action.php page where the form action is performed. It is suppose to redirect to next page if login credentials match and alert messages otherwise. This is my login_action form php.
<?php
session_start();
include("connect.php");
session_unset($_SESSION['ok']);
session_unset($_SESSION['id']);
session_unset($_SESSION['user_id']);
$un = mysqli_real_escape_string($conn, $_POST['un']);
$pw = mysqli_real_escape_string($conn, $_POST['pw']);
$query = mysqli_query("SELECT * FROM tbl_users WHERE (username='$un' or email='$un')") or die(mysqli_error());
$num = mysql_num_rows($query);
if($num == 1)
{
while($row = mysqli_fetch_assoc($query)){
if(password_verify($pw, $row['password'])){
$_SESSION['submit']='ok';
$_SESSION['id']=$query['user_id'];
header("location:dashboard.php");
exit();
}
}
}
else
{
header("location:index.php?msg=wrong");
}
?>
and this is my screen after entering matching login credentials.

UPDATE: The code started executing now I don't know how because I haven't made any changes but the next time I tried logging in again mysqli_connect gave me No database selected error. This is my connect.php
<?PHP
error_reporting(0);
$conn = mysqli_connect("localhost","root","", "sts_nlg_test") or die('Cannot find database.');
?>