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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:18:00+00:00 2026-05-13T12:18:00+00:00

I am trying to make a function I can pass an mysql query into

  • 0

I am trying to make a function I can pass an mysql query into and get the result back or an error, it should also check to see if the user running the code is an admin, if they are then it will get a session variable that holds a number count of the mysql queries ran on the page and then increment it by 1 number and then set it back to a session, also if the user is an admin it will show any error messages.

I know it is not the best code but does it appear like it should work? Any tips to improve too please.

You can see that I am running another method that gets a session variables value, I then set it to a variable in the current method, I then increment it’s value by 1 number and then run the setter method to save it to a session again. I am not really sure If that is the correct way of doing that? DO I really need to run all those methods and save them all to a local variable like I am?

Also I am getting this error

Fatal error: Using $this when not in object context in C:\webserver\htdocs\project2\includes\classes\Database.class.php on line 37

Line 37 is this

$this->user_role = $session->get('user_role');

Method…

public static function query($sql)
{
    global $session; // the $session Object

    //get the session value to see if user is an admin
    $this->user_role = $session->get('user_role');

    //if user is admin, get query counter session value and +1 to it and reset it to a session variable.
    if ($this->user_role >= 9){
        $this->querie_counter = $session->get('querie_counter');
        $this->querie_counter++; // add +1 to the number
        $session->set('querie_counter',$this->querie_counter)
    }

    //run mysql query
    $result = mysql_query($sql);

    if (!$result) {
        // If admin is viewing then we show the SQL code and the error returned
        if($this->user_role >= 9){
            $error = '<BR><center><font size="+1" face="arial" color="red">An Internal Error has occurred.<BR> The error has been recorded for review</font></center><br>';
            $sql_formatted = highlight_string(stripslashes($sql), true);
            $error .= '<b>The MySQL Syntax Used</b><br>' . $sql_formatted .
            '<br><br><b>The MySQL Error Returned</b><br>' . mysql_error();
        }
        die($error);
    }
    return $result;
}
  • 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-05-13T12:18:01+00:00Added an answer on May 13, 2026 at 12:18 pm

    Hmm no one has read the error or?

    **Fatal error: Using $this when not in object context in C:\webserver\htdocs\project2\includes\classes\Database.class.php on line 37**
    

    ok you cant use $this in a static function you have to use self::users

    public static function query($sql)
    {
        global $session; // the $session Object
    
        //get the session value to see if user is an admin
        self::user_role = $session->get('user_role');
    
        //if user is admin, get query counter session value and +1 to it and reset it to a session variable.
        if (self::user_role >= 9){
            self::querie_counter = $session->get('querie_counter');
            self::querie_counter++; // add +1 to the number
            $session->set('querie_counter',$this->querie_counter)
        }
    
        //run mysql query
        $result = mysql_query($sql);
    
        if (!$result) {
            // If admin is viewing then we show the sql code and the error returned
            if(self::user_role >= 9){
                $error = '<BR><center><font size="+1" face="arial" color="red">An Internal Error has Occured.<BR> The error has been recorded for review</font></center><br>';
                $sql_formatted = highlight_string(stripslashes($sql), true);
                $error .= '<b>The MySQL Syntax Used</b><br>' . $sql_formatted .
                '<br><br><b>The MySQL Error Returned</b><br>' . mysql_error();
            }
            die($error);
        }
        return $result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 321k
  • Answers 321k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What about import operator auths = Author.objects.order_by('-score')[:30] ordered = sorted(auths,… May 14, 2026 at 12:42 am
  • Editorial Team
    Editorial Team added an answer When you create the symbol in Flash and export it… May 14, 2026 at 12:42 am
  • Editorial Team
    Editorial Team added an answer It will generally always be faster to store something calculated… May 14, 2026 at 12:42 am

Related Questions

I'm fairly new to php and I am trying to figure how do I
I am trying to use the getJSON function in jQuery to import some data
I'm trying to create my own error window for the project I am working
I am trying to make a function that opens a window but makes sure
I am trying to make a simple redirector controller in CakePHP. I'd like the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.