I am creating a web application which includes a log in and registration feature. There are two main users, clients and the 1 admin. I have so far been successfully able to create a registration page for the clients which links to a mySQL database.
And the log in page for both clients and admins. Upon log in the client or admin will be redirected to their respective dashboard.
The problem I am now facing is that - if anyone visiting the site types in the url to the trainers dashboard they will be granted full access and admin privledges. I want a message to appear saying something like 'PLEASE LOG IN'
This is a snippet of the code I am currently using in my 'login.php' file:
   <?php
if (!isset($_POST['submit'])){
?>
<!-- The HTML login form -->
    <center><form action="<?=$_SERVER['PHP_SELF']?>" method="post">
        <div class="form-group">
                <input type="text" name="username" id="username" class="form-control input-lg" placeholder="Username" tabindex="3">
            </div>
        <div class="form-group">
                 <input type="password" name="password" id="password" class="form-control input-lg" placeholder="Password" tabindex="5">
            </div>
        <br /> <br /><input type="submit" name="submit" class="btn btn-success btn-block btn-lg" value="Login" /> </center>
    </form>
<?php
} else {
    require_once("db_const.php");
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    # check connection
    if ($mysqli->connect_errno) {
        echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
        exit();
    }
    $username = $_POST['username'];
    $password = $_POST['password'];
    $tusername = $_POST['username'];
    $tpassword = $_POST['password'];
    $sql = "SELECT * from client WHERE Client_username LIKE '{$username}' AND Client_password LIKE '{$password}' LIMIT 1";
    $result = $mysqli->query($sql);
    if (!$result->num_rows == 1) {
        echo "<p>Invalid username/password combination</p>";
    } else {
        header('location:client_dash.html?msg=success');
    }
    $sql = "SELECT * from trainer WHERE trainer_username LIKE '{$tusername}' AND trainer_password LIKE '{$tpassword}' LIMIT 1";
    $result = $mysqli->query($sql);
    if (!$result->num_rows == 1) {
        echo "<p>Invalid username/password combination</p>";
    } else {
        header('location:trainer_dash.php?msg=success');
    }
}
?>
 
     
     
    