It looks like your not sticking to the MVC pattern. You should be passing the data from view -> controller -> model.
As for sending information to the database, I'm pretty sure that CI handles xss and filter input, but you can never be to sure.
Also make sure you are loading your models in the config/autoload.php file or initiate the model in the controller __construct() function
<?php
class User extends CI_Controller
{
public __construct()
{
parent::__construct();
$this->load->model('User_model');
}
}
or
$autoload['model'] = array('User_model');
So for example in my login view, I would have the CI create the fields needed.
<?php
echo form_open('admin');
echo form_label('Username:', 'username');
echo form_input('username', 'name');
echo form_label('Password:', 'password');
echo form_password('password');
echo form_submit('submit', 'Login', 'id="loginBtn"'); ?>
echo form_close();
?>
Now in the controller
<?php
class User extends CI_Controller
{
public function index()
{
$this->load->model('User_model');
$result = $this
->user_model
->index(
$this->input->post('username'),
$this->input->post('password'));
}
}
?>
And the model
<?php
class User_model extends CI_Model
{
function index($username, $password)
{
$q = $this
->db
->where('username', $username)
->where('password', md5($password))
->limit(1)
->get('user');
if ($q->num_rows() > 0) {
return $q->row();
}
}
}