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 8701145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:19:34+00:00 2026-06-13T02:19:34+00:00

I’ve been been on this for hours trying to find the small mistake I’ve

  • 0

I’ve been been on this for hours trying to find the small mistake I’ve done and I just can’t find it… All I’m doing is calling a variable as global in a function and it’s just not working even though it worked fine with the function above it…

I get an error saying mysqli is null…

include 'data/mysqli_connect.php'; 

function process_login(){

global $mysqli;

$username = $_SESSION['username'];


$sql = "SELECT * FROM auth WHERE user='".mysqli_real_escape_string($mysqli,$username)."'";
$query = mysqli_query($mysqli,$sql);


if(mysqli_num_rows($query)>0){

$sql = "DELETE FROM auth WHERE user='".mysqli_real_escape_string($mysqli,$username)."'";
$query = mysqli_query($mysqli,$sql);


if(!$query){

die(mysqli_error());

}

}


$sql = "INSERT INTO auth (user, session) VALUES ('".mysqli_real_escape_string($mysqli,$username)."', '".$_SESSION['id']."')";
$query = mysqli_query($mysqli,$sql);

if(!$query){

echo "Can not insert info into database!<br />". mysqli_error();

}else{

header("Location:chat.php");

}

}


function logout(){

global $mysqli;

$sql = "DELETE FROM auth WHERE session='".mysqli_real_escape_string($mysqli,$_SESSION['id']). "'";
$query = mysqli_query($mysqli,$sql);


if(!$query){

echo "Can not delete info from database!";

}else{

session_destroy();
header("Location: chat.php");

}

}


function get_username(){

global $mysqli;


$sql = "SELECT * FROM auth WHERE session='".mysqli_real_escape_string($mysqli,$_SESSION['id']). "'";
$query = mysqli_query($mysqli,$sql);
$row = mysqli_fetch_array($query);


if(mysqli_num_rows($query) == "0"){

$username = "Guest";

}else{

$username = $row['user'];

 }

 return $username;

}



function post_message(){

global $mysqli;

$text = addslashes(htmlentities(htmlspecialchars($_REQUEST['text'])));


$sql = "INSERT INTO chat (time, user, text) VALUES ('".date("H:i")."', '".get_username()."', '".$text."')";

$query = mysqli_query($mysqli,$sql);


if(!$query){

die(mysqli_error());

}

}

    mysqli_connect.php
    $mysqli = mysqli_connect(localhost, "info", "info", "info");

Like I said it worked on the function above this one but not this one, it doesn’t make sens… I’m guessing I have a stupid mistake in there somewhere just don’t know where.

By the way,the functions that I tested and work are process_login() and logout() and get_username()

get_username() runs first then process_login(). post_message() runs from a jquery code that calls it when i press on enter that probably works fine since i can see the error code when i press enter.

Oh and sorry about the bad code formatting,not sure how to fix it on here.

Thank you for any help or advice you may find.

  • 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-13T02:19:35+00:00Added an answer on June 13, 2026 at 2:19 am

    How/When is post_message() called? From what you edited in, I can’t find anything specifically in that that would clear the $mysqli variable – but to debug it, we would need more of the program flow.

    Or you could create a ‘hack’ in the code and within post_message() after you declare global $mysqli;, do include 'data/mysqli_connect.php'; again since the $mysqli reference to your DB connection has been lost by then. But, ideally, you need to follow the flow of your code to figure out where to fix it correctly – and your flow seems not to be able to be posted fully, or is too great to post fully here.

    (Too long for a comment, so this response comes in answer form, my apologies.)

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has

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.