Question: I have a variable named '**`$uname`**' in a function from controller and I need to print the '`$uname`' value in the '`login_form_success`' under view. 

**login.php**

```
public function uname_exist($uname) {
        $this->db->where('username', $uname);
        $query = $this->db->get('login');
        if (!$query->num_rows() > 0) {
            $this->form_validation->set_message(__FUNCTION__, 'Invalid Username');
            return FALSE;
        } else {

            return TRUE;
        }
    }

```

login\_form\_success.php

```
<div class="alert alert-success">Welcome <?php echo $uname; ?> Signed in !</div>

```

Answer: 
You can save the value in **\_SESSION** array as 

```
session_start();
$_SESSION['uname'] = $uname;

```

and use the same value anywhere by using 
`$_SESSION['uname']`
```
public function uname_exist($uname) {
        $this->db->where('username', $uname);
        $query = $this->db->get('login');
        if (!$query->num_rows() > 0) {
            $this->form_validation->set_message(__FUNCTION__, 'Invalid Username');
            $uname = "not exist";

        } else {
            $uname = "exist";

        }
        return $uname;
    }

```

use the $name return, and your html can got it by the same var name.

and better 

```
public function uname_exist($uname) {
        $this->db->where('username', $uname);
        $query = $this->db->get('login');
        if (!$query->num_rows() > 0) {
            $this->form_validation->set_message(__FUNCTION__, 'Invalid Username');
            $unamehave = 'new person';

        } else {
            $unamehave = $uname;

        }
        return $unamehave;
    }

```

`<div class="alert alert-success">Welcome <?php echo $unamehave; ?> Signed in !</div>`