I'm still new to PHP and I want to create a login page which keeps track of the users (teacher and students). My code is already working, but I get some warnings if the user enters an invalid username and password. Does anyone know how to fix this?
Here is the warning:
$user_type=$_POST["type"];
Warning: Undefined array key "type"
$row["type"]=="teacher"
Warning: Trying to access array offset on value of type null
$row["type"]=="student"
Warning: Trying to access array offset on value of type null
Here is the code:
$username=$_POST["username"];
$password=$_POST["password"];
$user_type=$_POST["type"];
$sql="SELECT * FROM user WHERE username= '".$username."' AND password= '".$password."' AND
type= '".$user_type."' ";
$result=mysqli_query($data,$sql);
$row=mysqli_fetch_array($result);
if($row["type"]=="teacher"){
$_SESSION["type"]=$username;
echo "teacher";
}elseif($row["type"]=="student"){
$_SESSION["type"]=$username;
echo "student";
}