Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:51:02+00:00 2026-06-17T15:51:02+00:00

in my code below it is not able to recognise the variable $userid ,

  • 0

in my code below it is not able to recognise the variable $userid, this variable determines the id of the teacher logged in but in the mysqli code it is not able to determine the $userid when I echo it. But it does know the user is logged in by its $userid. So my question is that in the mysqli why is it unable to find the $userid? Please look at comment in mysqli bind_param() setion and this is where the problem is.

Below is the code, both php and mysqli:

Let me state that member.php is the script which contains the $userid info:

    <?php
     session_start();

        include('member.php');

    ...

        function PickSession()
        {

            //Get data from database
            $sessionquery = "
                SELECT s.SessionId, SessionName, s.TeacherId
                FROM Session s
                INNER JOIN Session_Complete sc ON sc.SessionId = s.SessionId
                WHERE
                (ModuleId = ? AND Complete = ? AND s.TeacherId = ?)
                ORDER BY SessionName 
                ";
            $complete = 1;

            global $mysqli;
            $sessionqrystmt=$mysqli->prepare($sessionquery);
            // You only need to call bind_param once
            $sessionqrystmt->bind_param("iii",$moduleId, $complete, $userid);//it doesn't recognse $userid
            // get result and assign variables (prefix with db)
            $sessionqrystmt->execute(); 
            $sessionqrystmt->bind_result($dbSessionId,$dbSessionName,$dbTeacherId);
            $sessionqrystmt->store_result();
            $sessionnum = $sessionqrystmt->num_rows();  

echo $userid; //nothing displayed in this echo
    ...

            if ((isset($username)) && (isset($userid))){ //user is successfully logged in

            include('teachername.php');

    ...

        <?php


        ShowAssessment(); // Show information



            }else{ 

    echo "Please Login to Access this Page | <a href='./teacherlogin.php'>Login</a>";

    }

            ?>

member.php script:

if (isset($_SESSION['teacherid'])) {

      $userid = $_SESSION['teacherid'];

  }

if (isset($_SESSION['teacherusername'])) {

      $username = $_SESSION['teacherusername'];

  }

        ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:51:03+00:00Added an answer on June 17, 2026 at 3:51 pm

    You have not initialised the $userid variable, you have to set the value for binding the variable in query otherwise it will take NULL value for that variable.

    $userid = "value";
    $sessionqrystmt->bind_param("iii",$moduleId, $complete, $userid);
    

    The $userid variable is not accessible in PickSession(). So the suggestion is either make $userid as global or pass it as parameter in function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried rectifying the code below. But I am not able to find
HI I wanna timeout session from client page,i tried below code but not able
The code below does not work but meant to illustrate what I want to
Below code not work, but it's work fine for jsf1.2. Now the framework is
W.r.t code below I can not declare the type of fetch-into-variable as the underlying
Getting vector iterator not deferencable for code below, but I don't see why. I
The code below is working, but with a problem I do not understand. When
I am not able to understand the error with the code below which simply
In my application I'm able to get all MMS through code below, but I
In the code below I am not able to understand the way in which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.