Home » Php » php – using SESSION to redirect to admin page

php – using SESSION to redirect to admin page

Posted by: admin February 25, 2020 Leave a comment


I have a admin login form which checks if the user exits in mysql database. what i am trying to do now is implement SESSION so after the admin user logs in they will be redirected to the admin user page

        require_once "connection.php";
        if (isset($_POST['username'])) {
        if(count($_POST)>0) {

            $result = mysqli_query($con,"SELECT * FROM admin_doctor WHERE username='" . $_POST["username"] . "' and password = '". $_POST["password"]."'");
            $count  = mysqli_num_rows($result);
            if($count==0) {
                $message = "Invalid Username or Password!";
            } else {
                 $_SESSION['username'] = $username;
                    header("Location: admin-backend.php");

        <div class="admin-page">
              <div class="form-admin">
                <form class="admin-form" action="" method="post">
                <div class="message"><?php if($message!="") { echo $message; } ?></div>
                  <input type="username" name="username" placeholder="username" value="" maxlength="30" required=""/>
                  <input type="password" name="password" placeholder="Password" value="" maxlength="8" required=""/>
                  <input type="submit" class="login-button"  name="submit" value="Login">
How to&Answers: