I’m creating a login form with Codeigniter, and I have a controller that collects the inputs from the form, then I want to check to make sure what the user entered is in the database, so I’m collecting those values in the post and want to send them to the model for the database connection. Then if the results are in the database I want to send something back to the controller with a yes or no and then I can go from there. I’m kind of stuck, but this is what I have so far:
The controller:
function do_login()
{
$login = $this->input->post('Login');
$pwd = md5($this->input->post('Passwd'));
}
The Model:
function check_login()
{
$sql = $this->db->query("SELECT * FROM members WHERE loin = '?' AND password = '?'", array(//POST stuff goes in here));
return $sql->result();
}
I’m not sure how to pass the data to the model, and then back to the controller.
Any help would be great!
Thanks!
In any MVC form POST is sending to controller (in action property in form) and controller (as the name is decribed) controls what will happend, in your case should ask database for verification via model, get response, decide what to do, and use view to display results…
so in your controller:
function do_login() { $login = $this->input->post('Login'); $pwd = md5($this->input->post('Passwd')); $results = $this->...your_model_name...->chek_login( parameters as login and password would help ) // base on results: has records or has not - do something // maybe display view }