I just started learning PHP awhile ago and I am starting a new project. When I am trying to call a global varible it gives me an undefined variable error. I have had many people look over this code and no one seems to know the issue.
<?php
$UserID = 0;
$UserName = "Mark";
$TalkingToUserID = 1;
$TalkingToUserName = "Dalton";
$chatLog = fopen($UserID . "T" . $TalkingToUserID . ".txt", "w") or die("Unable to open file!");
function writeToFile($txt){
fwrite($chatLog, "\n" . $txt);
fclose($chatLog);
}
writeToFile("Hello");
?>
It's saying: Notice: Undefined variable: chatLog in Messenger.php on line 18 for all varibles I have declared.