Login with multiple tables (v2022)

I have two table: tbl_users and tbl_profiles. The tbl_users is set as default table for login. I would like that when the login account is not present in tbl_users, it will search from tbl_profiles . Here is my code but not working

// User Logging In event
function User_LoggingIn($usr, &$pwd)
{
    // No match found in any table

    $sql = "Select count(*) from `tbl_users` where username='$usr' and user_password ='$pwd'";
	$c = ExecuteScalar($sql);
   	
    if ($c<=0)
    {

    	$sql1 = "Select count(*) from `tbl_profile` where username='$usr'
    	 and pass ='$pwd'";

    	 $c1= ExecuteScalar($sql1);

    	 if ($c1<=0)
    	 {
    	 //$this->setFailureMessage($c1); 
    	 return false;
    	 }
    	 else
    	 {
    	  //$this->setFailureMessage($c1); 
    	  return true;
    	 }
      	 
    }
    else
   {
   	return true;
   }


}

What did you mean by “not working”? What is exactly do you want to achieve?

In addition, you should double check your code, and if necessary, you should test those 2 SQL SELECT from your database manager application such as Navicat, whether it will return the expected result or not.

It only works if the user account is present in tbl_users. I want the program to search also the to the tbl_profile if the user account in not present in tbl_users

function User_LoggingIn($usr, &$pwd) {
    //
    $sql = "SELECT COUNT(*) FROM `tbl_users` WHERE username = '" . AdjustSql($usr) . "' AND user_password = '" . AdjustSql($pwd) . "'";
    $c = ExecuteScalar($sql);

    if ($c <= 0) {
        // 
        $sql1 = "SELECT COUNT(*) FROM `tbl_profile` WHERE username = '" . AdjustSql($usr) . "' AND pass = '" . AdjustSql($pwd) . "'";
        $c1 = ExecuteScalar($sql1);

        return $c1 > 0;
    }

    return true;
}