I have written a code to fetch the data from database, but its ended up with an error

> 
> A PHP Error was encountered
>  Severity: Notice
>  Message: Undefined index: username
>  Filename: views/userinfo.php
>  Line Number: 20
>  Backtrace:
> 
> 
> File: D:\wamp\www\anand\codeigniter\application\views\userinfo.php
>  Line: 20
>  Function: \_error\_handler
> 
> 
> File: D:\wamp\www\anand\codeigniter\application\controllers\Main.php
>  Line: 35 Function: view
> 
> 
> File: D:\wamp\www\anand\codeigniter\index.php Line: 315 Function:
>  require\_once
> 
> 
> 

My code is

```
?php
   $name=$this->session->username;
   $pass=$this->session->password;
   $q=$this->db->query("select * from signup where username='$name' and password='$pass'");
   $data=$q->result();
   echo $data['username'];
   echo $data['password'];
?>

```

kindly give a suggestion to fetch the data in a correct format..