php write succesful logins and unsuccesful to text file : Hey guys i've been trying to write my succesful logins/failed logins to a txt file but it doesn't work.
Can anyone please take a look at the code?

    if($_POST['username']==$username && $_POST['password']==$password)   // Check Given user name, password and Variable user name password are same
    
    {
    $_SESSION['username']=$username;    // set session from given user name
    
    
    
    header('location:mainpage.php');
    $logInData = date('Ymd-H:i:s');
    $logLogIn = fopen("../logs/logins.txt", "a");
    $txt = "\r\n$logInData, You logged in Succesfully";
    fwrite($logLogIn, $txt);
    fclose($logLogIn);
    
    }
    else
    {
    
    
    $err="Authentication Failed Try again!";
    $logInData = date('Ymd-H:i:s');
    $logLogIn = fopen("../logs/logins.txt", "a");
    $txt = "\r\n$logInData, Login failed wrong username or password";
    fwrite($logLogIn, $txt);
    fclose($logLogIn);
    
    }

I get the following errors : Warning: fwrite() expects parameter 1 to be resource, boolean given in /home/rans1600/public_html/D093G/moment2/index.php on line 32

Warning: fclose() expects parameter 1 to be resource, boolean given in /home/rans1600/public_html/D093G/moment2/index.php on line 33
Authentication Failed Try again! 