anyone know how to fix this i am new on coding ?Warning: Trying to access array offset on value of type null [duplicate]

//i got an error in part of $_SESSION cannot login as user and teacher even their usertype is correct in database but when manually input in database it was successfully login

    //if($data===false)
   // {
      //  die("connection error");
    //}
    //if($_SERVER["REQUEST_METHOD"]=="POST")
    //{   
        //$username=$_POST["username"];
        //$password=$_POST["password"];
       // $usert="user";
     //   $sql="select * from users where username = '".$username."' AND password = '".$password."'";
       // $result =mysqli_query($data,$sql);
       // $row=mysqli_fetch_array($result);
         //if($row["usertype"]=="admin")
       // {
           // $_SESSION["username"]=$username;
         //   header("location:admin.php");
       // }
       // else if($row["usertype"]=="user")
       // {
           // $_SESSION["username"]=$username;
         //   header("location:studenthome.php");
       // }
        // else if($row["usertype"]=="teacher")
       // {
           // $_SESSION["username"]=$username;
         //   header("location:teacherhome.php");
       // }
        
       // else{
       //     echo "username and password incorrect";
     //   }
    //}