How to access html element in php

I want to display message to user in html page that the email or password is wrong when he put wrong data.
I have

<small id="messages" class="text-danger"></small>

and in the php file:

if(!empty($row)){
        // checking password
        // unhasing password
        if(password_verify($password, $row['password'])){
            //when user correctly log in set user id
            session_start();
            $_SESSION['userID'] = $row['userID'];   
            header('location: user-profile.php');
            exit();
        } else {
            echo "You are not a member";
        }
    } else {
        echo "Please fill out!";
        
    }

and I want to echo ‘ Your are not a member’ actually show up in the small tag if the condition is correct. I know how to do that in js, but can I put js code in php? What is the correct way to actually done that?