LeviZoesch
LeviZoesch

Reputation: 1621

php Warning & Strict Standards

I am using $_SESSION['']; to get values from a user after they have logged in. This data is coming from the users table.

I am then trying to

`SELECT *` `FROM roster`

by doing a query and assigning a var for each value when the users API=$API

I can do so by using the following:

error_reporting(E_ALL);

    include ('database_connection.php');
    $API        = $_SESSION['API'];

        if ($API !== false) { 
            $roster_query = "SELECT * FROM roster WHERE API='$API'";
            $result = mysqli_fetch_array(mysqli_query($dbc, $roster_query));

    /* ROSTERS TABLE */
            $StreetName     = $result['streetname'];
            $HouseNum   = $result['housenumber'];
            $City       = $result['city'];
            $State      = $result['state'];     
            $Zipcode        = $result['zipcode'];                               

    /* SESSION */
            $FirstName  = $_SESSION['firstname'];
            $LastName   = $_SESSION['lastname'];
            $Email      = $_SESSION['email'];

    /* this->$vars - Specific for this form */      
            $ExecutionDate  = date("Y:M:D");      
            $DOCSIGNEDBYIP  = $_SERVER['REMOTE_ADDR'];

        }

However, I get the following errors when I do. If I remove the above code no errors, etc.

Now this isnt 'breaking' my code, but I do not want to sweep this under the rug and resolve later.

Can someone identify where I am going wrong ?

Warning: Creating default object from empty value in /home/.../public_html/.../.../.../db.php on line 48

line 48: $return->$i = $row;

if(!$return_array) {
    while($row = mysql_fetch_object($sql_query)) {
        $return->$i = $row;
        $i++;
    }

Strict Standards: Non-static method Access::is_logged() should not be called statically, assuming $this from incompatible context in /home/.../public_html/.../.../.../APP.php on line 64

pinAPP line 64: return Access::is_logged();

public function is_logged()
    {
        return Access::is_logged();
    }

is_logged();

   <?php
    require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'init.php');

    class pinAPP {


        public function is_logged() {
            return Access::is_logged();
        }

    }

Access

<?php
    class Access {
        private static $auth = false;


        final public function is_logged( $require_admin_access = false ) {
            if ( ! isset($_SESSION[LOGINSESSION]) )
                return false;

            self::$auth = true;

            if ( $require_admin_access ) {
                $u = new User();
                if ( ! $u->is_admin() )
                    new Redirect(DEFAULT_RETURN_URL);
            }

            return self::$auth;
        }

    }

Upvotes: 1

Views: 91

Answers (2)

Rasclatt
Rasclatt

Reputation: 12505

Try these, see if they work:

// Set an empty object for $return first
$return =   new stdClass();

if( ! $return_array ) {
    $i = 0;
    while ( $row = mysql_fetch_object($sql_query) ) {
        $return->$i = $row;
        $i++;
    }

I think the other is saying you should have is_logged() as a static function:

class Access
    {
        static function is_logged()
            {
                // code here
            }
    }

Upvotes: 2

Tobi
Tobi

Reputation: 31

  1. check $row use !empty($row) (just Warning)
  2. can not find static functon is_logged()

Upvotes: -1

Related Questions