$_SESSION inside php function executed by AJAX

Wrapping this line inside if statement solved the problem:

if(!isset($_SESSION['session_test'])) {
    $_SESSION['session_test'] = $_POST['reason'];
}

I thought select_return_reason(){...} function which is holding this line was executing only by AJAX, not on each page load.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)