Q: Notice: Undefined variable: login i have this code
<?php

$host = "localhost";
$user = "root";
$pass = "";
$dabname = "tutorial";

$login = mysqli_connect($host, $user, $pass, $dabname) or die('Could not connect to mysql server.');
mysqli_select_db($login, $dabname) or die('Could not select database.');
$nama_karyawan = $_POST['nama_karyawan'];
$umur_karyawan = $_POST['umur_karyawan'];

function proses_hoby($id_karyawan) {
    if (isset($_POST["rincian_hoby"])) {
        $hoby = $_POST["rincian_hoby"];
        reset($hoby);
        while (list($key, $value) = each($hoby)) {
            $rincian_hoby = $_POST["rincian_hoby"][$key];
            $jenis_hoby = $_POST["jenis_hoby"][$key];
            $sql_hoby = "INSERT INTO tbl_hoby(rincian_hoby,jenis_hoby,id_karyawan)
                                              VALUES('$rincian_hoby','$jenis_hoby','$id_karyawan')";
            $hasil_hoby = mysqli_query($login, $sql_hoby);
        }
    }
}

$sql = "INSERT INTO tbl_karyawan(nama_karyawan,umur_karyawan)
                      VALUES('$nama_karyawan','$umur_karyawan')";
$hasil = mysqli_query($login, $sql);
$id_karyawan = mysqli_insert_id($login);
if ($hasil) {
    proses_hoby($id_karyawan);
    echo "Data berhasil diinput";
} else {
    echo "Data Gagal diinput";
}
?>

But i do get this error

Notice: Undefined variable: login in C:\xampp\htdocs\2\proses.php on
  line 23
Warning: mysqli_query() expects parameter 1 to be mysqli, null given
  in C:\xampp\htdocs\2\proses.php on line 23
Notice: Undefined variable: login in C:\xampp\htdocs\2\proses.php on
  line 23
Warning: mysqli_query() expects parameter 1 to be mysqli, null given
  in C:\xampp\htdocs\2\proses.php on line 23 
  Data berhasil diinput

I know there are lot of similiar Thread name but i dont found that match my problem
Here is the source code https://drive.google.com/file/d/16FNr5SJeO_53_-XUJo7RIV1rLqgZwagV/view?usp=sharing
please help
any help would be very appreciated
thank you

A: You should learn about variable scopes inside php. $login is declared outside the function proses_hoby so proses_hoby can't access this var. To access $login inside the function, you need to make it global (the unclean way..) or pass $login as an function parameter.
Modern approaches would be to move the whole thing inside a class and make $login a class var. So every member of the class could access the var.
Btw. your code is prone to sql injections. You should use prepared statements.
