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

  • Home
  • SEARCH
  • 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 8687897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:13:43+00:00 2026-06-12T23:13:43+00:00

lately I’ve been getting an error undefined variable mysqli and I was wondering –

  • 0

lately I’ve been getting an error undefined variable mysqli and I was wondering – is it because I’m accessing two different tables in the same database?

$mysqli = new mysqli('localhost', 'myuser', 'qwerty', 'mydb');

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
    //initialise vars
    $username = $_POST['username'];

    $checkRecord = $mysqli->query("SELECT information, blahblah FROM table1 WHERE username='$username' AND field1='$field1' AND field2=$field2");

    if(!$checkRecord->num_rows) 
    {
        echo "nothing retreived";
    }   
    else
    {
        $catch = $checkRecord->fetch_object();

        $newsessionnumber = get_new_session_number($username, $ip, $userAgent);

        $senddata = array(
            'newsessionnumber' => $newsessionnumber,
            'info' => $catch->information, 
            'blahblah' => $catch->blahblah, 
            'username' => $username 
        );

        echo json_encode($senddata); 
    }   
}

function get_new_session_number($username, $ip, $userAgent)
{   
    $mysqli->query("INSERT INTO sessionnumberdispatch VALUES (NULL, '$username', NOW(), '$ip', '$userAgent')");

    $newsessionnumber = $mysqli->insert_id;
    return $newsessionnumber;       
}
  • 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-12T23:13:46+00:00Added an answer on June 12, 2026 at 11:13 pm

    The $mysqli object is not getting recognized inside get_new_session_number().

    Use the global keyword:

    function get_new_session_number($username, $ip, $userAgent)
    {   
        global $mysqli;
        $mysqli->query("INSERT INTO sessionnumberdispatch VALUES (NULL, '$username', NOW(), '$ip', '$userAgent')");
    
        $newsessionnumber = $mysqli->insert_id;
        return $newsessionnumber;       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lately, I've been wondering how to find the difference between two files with PHP.
Lately I've been using git show <hash> to create diffs for later reference because
Lately, I've gotten some weird linker errors. I've been taught that there's two ways
Lately I've been wondering if there's a difference between initializing the variables that have
Lately we've been getting into a bit of co-development, and I don't think I'm
Lately my site has been getting hit by some people who have bots which
Lately I have been trying my hands on Eclipse IDE for java development. I
Lately I've been favoring using named pipes (option --enable-named-pipes) in MySQL running on windows,
Lately, I'v been struggling with an annoying situation on ASP.NET MVC. Here's the story
Lately we've started getting issues with outdated countries / regions list being presented to

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.