How to insert login date and time in db using codeigniter?

This is my model code

class front_model extends CI_Model {
	public function login(){
		$this->db->where('username',$this->input->post('username'));
		$this->db->where('password',md5($this->input->post('password')));
		$result = $this->db->get('auth_user');
		if($result->num_rows() > 0){
			$result = $result->row();
			$data = array(
				'id'		=> $result->id,
				'username'	=> $result->username,
			);
			$this->session->set_userdata($data);
			return true;
		}else{
			return false;
		}

Hi @pkpathak1994 and welcome to the forums.

Check out PhpMyAdmin and the fields setting. A column can be set that inserts a timestamp whenever the record is updated.

table_name = auth_user
column = last_login
data_type = datetime

Try this:

Just one click to change the field attribute to ‘ON_UPDATE_SET_CURRENTTIMESTAMP‘

thnx

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.