Jump to content

Call to a member function _safestring() on a non-object


PHPiSean

Recommended Posts

When I use another class inside one class, I get this error

 

Call to a member function _safestring() on a non-object

 

The code is here

<?php

    require ('db.inc.php');
    $db = new db();
    
class common {
    
    function _cookiecheck() {
        if(!isset($_SESSION['username'])) {
            if(isset($_COOKIE['username'])&&isset($_COOKIE['password'])) {
                $pass = $db->_safestring($_COOKIE['password']);
                $user = $db->_safestring($_COOKIE['username']);
                $check = _query("select password from users where username='{$user}'");
                 if($check) {
                     $_SESSION['username'] = $user;
                 }
            }
        }
    }
    

}

?>

 

I get the error on the line when I call $db->_safestring();

 

Thanks for the help

Link to comment
Share on other sites

I would suggest reading:

 

http://php.net/manual/en/language.oop5.php

 

To learn where you are going wrong with that. Aside from that, here is probably what you are doing:

 

<?php    
class common {
        require ('db.inc.php');
    $db = new db();

    function _cookiecheck() {

 

 

Here is one way to do it:

 

<?php    
require ('db.inc.php');

class common {
    function _cookiecheck() {
              $db = new db();

 

Which will work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.