Hello guys, i'm trying to show the full name of my user what is logged in. I am new to writing in oop. Im getting a undifined index fullname error. Can anyone help me?

  /*** for showing the username or fullname ***/
  public function get_fullname($userid)
  {
         $stmt = $this->db->prepare("SELECT fullname FROM users WHERE   userid = $userid");  
        $stmt->execute();

    /* Fetch all of the remaining rows in the result set */
    $user_data = $stmt->fetchAll();
    echo $user_data['fullname'];


  }

Recommended Answers

and don't put php variables directly in to the SQL query use bind_param instead http://php.net/manual/en/mysqli-stmt.prepare.php

Jump to Post

All 2 Replies

Try :

echo $user_data[0]['fullname'];

since fetchAll returns a set of all the rows (only one in your case).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.