PHP – Notice: Undefined index [duplicate]

I am doing a hospital management project I got an error while doing it can anyone solve it

<?php 
include("include/connection.php");
if (isset($_POST['apply'])) {
    $firstname=$_POST['fname'];
    $surname = $_POST['sname'];
    $username = $_POST['uname'];
    $email = $_POST['email'];
    $gender = $_POST['gender'];
    $phone = $_POST['phone'];
    $country = $_POST['country'];
    $password = $_POST['pass'];
    $confirm_password = $_POST['con_pass'];


    $error=array();



    if (empty($firstname)) { 
        $error[ 'apply'] = "Enter Firstname";
    }else if(empty($surname)){
        $error['apply'] = "Enter Surname";
    }else if (empty($username)){
        $error['apply'] = "Enter Username";
    }else if(empty($email)){
        $error['apply'] = "Enter Email Address";
    }else if($gender == ""){
        $error[ 'apply']="Select Your Gender";
    }else if(empty($phone)){
        $error['apply'] = "Enter Phone Number";
    }else if($country == ""){
        $error['apply'] = "Select Country";
    }else if (empty($password)){
        $error['apply'] = "Enter Password";
    }else if($confirm_password != $password){
        $error[ 'apply'] = "Both Password do not match";
    }

}

I am getting the following errors
this is showing while running it
it is very help full if anyone answer it