#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    France
    Posts
    205
    Rep Power
    18

    Notice: Trying to get property of non-object


    Can anyone help me with this:

    I'm returning

    Notice: Trying to get property of non-object in....
    Notice: Trying to get property of non-object in....
    Notice: Trying to get property of non-object in....

    Number of rows: 1

    So the result set is not NULL

    PHP Code:

    $result 
    $connection->query("SELECT * FROM $table_name WHERE username = '$user' and password = password('$pass')");

    $rows mysqli_num_rows($result); 

    if (
    $rows) {     
        
        while (
    $row mysqli_fetch_array($result)) 
                    {         

    $_SESSION['first_name']        = $row -> firstname;
    $_SESSION['last_name']     = $row -> lastname
    $_SESSION['user_name']     = $row -> username

                    } 
                } 

    echo 
    "Number of rows: $result->num_rows"
    What does the notice mean and why am I getting it?

    Tks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,473
    Rep Power
    653
    $row is not an object in this context, it is an associative array and numeric array.
    PHP Code:
    $_SESSION['first_name']=$row['firstname']; 
    or
    PHP Code:
    $_SESSION['first_name']=$row[0]; 
    You can also specify only one or the other with a 2nd parameter to the fetch method (MYSQLI_NUM for numeric or MYSQLI_ASSOC for associative).
    Last edited by gw1500se; August 19th, 2018 at 10:33 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Location
    France
    Posts
    205
    Rep Power
    18
    Yes I just twigged it's an array - thanks very much for the reply. I like the binary thing.
  6. #4
  7. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,914
    Rep Power
    9646
    Please don't lock your threads once you get an answer. People may have something more to add.

IMN logo majestic logo threadwatch logo seochat tools logo