I have created a login function for my website but it keeps on giving me the error that there is an undefined variable. The variable it is referring to is the $conn variable which i have defined in server.php file. Below is the code for my function:
function loginValidation($username, $password, $rememberMe){
    $newPassword = md5($password);
    $userValidation = mysqli_query($conn, "SELECT * FROM users WHERE username='$username' && password='$newPassword' OR email='$username' && password='$newPassword' ");
    $userValidationNum = mysqli_num_rows($userValidation);
    if($userValidationNum == 1):
        $_SESSION["cf_username"] = $username;
            if($rememberMe == 1):
                $hour = time() + 3600 * 24 * 30;
                setcookie('username', $username, $hour);
                setcookie('password', $password, $hour);
            endif;
        header("location:index.php");
    else:
        header("location:login.php?msg=Incorrect Username or Password");
    endif;
    
}
Here is the code for the server.php file as well and yes i have included the server.php file in the main file
$conn = mysqli_connect("localhost", "root", "protocol1", "crossfield-portal");
// Check connection
if(mysqli_connect_errno()):
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
endif;
session_start();
I am calling the function from login.php. This is the code:
if(isset($_POST['submit'])):
if(isset($_POST['rememberMe'])):
  $rememberMe = $_POST['rememberMe'];
else:
  $rememberMe = 0;
endif;
loginValidation($_POST['email'], $_POST['password'], $rememberMe);
endif;
Any help would be appreciated. Thanks.
 
    