title: Is this a safe way of making user access level using PHP MySQL?
body: <p>I am making a user access level in PHP. I wrote some code it worked and redirects the user to their respective pages, but I am not sure is it a safe way of doing it. </p>
  
  <pre><code>if(filter_has_var(INPUT_POST, "signin")){
      $firstname = $_POST["firstname"];
      $password_1 = $_POST["password_1"];
  
      $sql = "SELECT * FROM users WHERE firstname = :firstname";
      $stmt = $conn-&gt;prepare($sql);
      $stmt-&gt;execute(["firstname" =&gt; $firstname]);
      $res = $stmt-&gt;fetch();
      $password = $res["password_1"];
  
      if(password_verify($password_1, $password)){
          // USER ACCESS LEVEL
          if($res["user_type"] == "student"){
              $_SESSION["username"] = $firstname;
              header("location: index_s.php?type=student");
          } else if ($res["user_type"] == "teacher"){
              $_SESSION["username"] = $firstname;
              header("location: index_t.php");
          } else {
              $_SESSION["username"] = $firstname;
              header("location: index.php");
          }
      } else {
          array_push($errors, "Invalid username/password entered!");
      }
  }
  </code></pre>
  
  <p>I have a user_type column in my user table wherein user identifies which type of user he is while signing up and based on that they are redirected to their respective pages when they log in. 
  However, this code works but I think this is not the right way of doing it. I need your help and feedback to improve the quality of my code. Also I am new in programming please explain clearly. </p>