Php 不显示会话数据中的用户角色

Php 不显示会话数据中的用户角色,php,Php,我试图从会话数据中获取用户角色,但每次尝试时都会出现一个错误,即 致命错误:未捕获ArgumentCounter错误:参数太少,无法 函数getUserAccessRoleByID(),传入1 第7行和第2行的G:\xampp\htdocs\highballSystem\index.php 预计在 G:\xampp\htdocs\highballSystem\includes\functions.inc.php:117堆栈 跟踪:#0 G:\xampp\htdocs\highballSystem

我试图从会话数据中获取用户角色,但每次尝试时都会出现一个错误,即

致命错误:未捕获ArgumentCounter错误:参数太少,无法 函数getUserAccessRoleByID(),传入1 第7行和第2行的G:\xampp\htdocs\highballSystem\index.php 预计在 G:\xampp\htdocs\highballSystem\includes\functions.inc.php:117堆栈 跟踪:#0 G:\xampp\htdocs\highballSystem\index.php(7): getUserAccessRoleByID(NULL)#1{main}已抛出 G:\xampp\htdocs\highballSystem\includes\functions.inc.php,第117行

用户角色是从mymymysql数据库的myusers表中的一列加载的。这些角色存储在一个sperate表tbl_user_role中。任何帮助都将不胜感激。我试着四处寻找修复方法,但真的找不到任何有意义的东西

Functions.php

function loginUser ($conn, $username, $pwd){
    $uidExists = uidExists($conn, $username, $username);

    if ($uidExists === false) {
        header("location: ../login.php?error=wronglogin");
        exit();
    }

    $pwdHashed = $uidExists ['usersPwd'];
    $checkPwd = password_verify($pwd, $pwdHashed);
    if ($checkPwd === false) {
        header("location: ../login.php?error=wronglogin");
        exit();
    }else if ($checkPwd === true) {
            session_start();
            $_SESSION["userid"] = $uidExists ["usersId"];
            $_SESSION["useruid"] = $uidExists ["usersUid"];

            header("location: ../index.php");
            exit();
    } 
}

function getUserAccessRoleByID($id)
{
    $sql = "SELECT user_role FROM tbl_user_role WHERE id = ?;";
    $stmt = mysqli_stmt_init($conn);
 if (!mysqli_stmt_prepare($stmt, $sql)) {
    header("location: signup.php?error=stmtfailed");
        exit();
 }
    mysqli_stmt_bind_param($stmt, "i", $id);
    mysqli_stmt_execute($stmt);

    $resultData = mysqli_stmt_get_result($stmt);

    if ($row = mysqli_fetch_assoc($resultData)) {
        return $row;
    }
    else{
        $result = false;
        return $result;
    }
}
<?php 
include_once 'header.php';
?>
<?php  
                    if (isset($_SESSION["useruid"])) {
                        echo "<p>Hello there " . $_SESSION["useruid"] . "</p>";
                        echo "You are logged in as <strong>". getUserAccessRoleByID($_SESSION['user_role'])."</strong>";
                    }
                ?>
<?php 
include_once 'footer.php';
?>
Index.php

function loginUser ($conn, $username, $pwd){
    $uidExists = uidExists($conn, $username, $username);

    if ($uidExists === false) {
        header("location: ../login.php?error=wronglogin");
        exit();
    }

    $pwdHashed = $uidExists ['usersPwd'];
    $checkPwd = password_verify($pwd, $pwdHashed);
    if ($checkPwd === false) {
        header("location: ../login.php?error=wronglogin");
        exit();
    }else if ($checkPwd === true) {
            session_start();
            $_SESSION["userid"] = $uidExists ["usersId"];
            $_SESSION["useruid"] = $uidExists ["usersUid"];

            header("location: ../index.php");
            exit();
    } 
}

function getUserAccessRoleByID($id)
{
    $sql = "SELECT user_role FROM tbl_user_role WHERE id = ?;";
    $stmt = mysqli_stmt_init($conn);
 if (!mysqli_stmt_prepare($stmt, $sql)) {
    header("location: signup.php?error=stmtfailed");
        exit();
 }
    mysqli_stmt_bind_param($stmt, "i", $id);
    mysqli_stmt_execute($stmt);

    $resultData = mysqli_stmt_get_result($stmt);

    if ($row = mysqli_fetch_assoc($resultData)) {
        return $row;
    }
    else{
        $result = false;
        return $result;
    }
}
<?php 
include_once 'header.php';
?>
<?php  
                    if (isset($_SESSION["useruid"])) {
                        echo "<p>Hello there " . $_SESSION["useruid"] . "</p>";
                        echo "You are logged in as <strong>". getUserAccessRoleByID($_SESSION['user_role'])."</strong>";
                    }
                ?>
<?php 
include_once 'footer.php';
?>


会话['user\u role']的价值是什么@gaurav它应该是tbl_user_role表中的角色名称。您确定没有定义两次
getUserAccessRoleByID
函数,因为错误提示它需要两个参数,但共享的代码只有一个参数argument@gaurav它只在functions.php文件中的一个位置定义,但错误为函数
getUserAccessRoleByID()
显示的参数太少,第7行传入了G:\xampp\htdocs\highballSystem\index.php中的1个参数,第7行预期正好是2个参数,我再次建议您检查
functions.inc.php中的117行