Php 在codeigniter中注销不起作用
嗨,伙计们,我正在尝试在我的codigniter中使用注销代码,所以由于某些原因,它不能正常工作 这是我的注销代码:Php 在codeigniter中注销不起作用,php,mysql,codeigniter,Php,Mysql,Codeigniter,嗨,伙计们,我正在尝试在我的codigniter中使用注销代码,所以由于某些原因,它不能正常工作 这是我的注销代码: public function Logout() { $this->Login_model->saveLogout(); $this->session->sess_destroy(); redirect('Login'); } 这是我的型号代码: public function saveLogout() { $r
public function Logout() {
$this->Login_model->saveLogout();
$this->session->sess_destroy();
redirect('Login');
}
这是我的型号代码:
public function saveLogout() {
$recordId=$this->session->userdata('user_id');
$ipaddress = $this->input->ip_address();
$dataLog = array(
'userid' => $recordId,
'entertime' => time(),
'ip' => $ipaddress,
'log_operation' => 'Logout'
);
$dataUser = array(
'previous_visit' => time(),
'lastip' => $ipaddress
);
$this->db->insert('log_table', $dataLog);
$this->db->set($dataUser); //value that used to update column
$this->db->where('id', $recordId); //which row want to upgrade
$this->db->update('users'); //table name
}
当我单击注销时,它显示以下错误
Column 'userid' cannot be null
INSERT INTO `log_table` (`userid`, `entertime`, `ip`, `log_operation`) VALUES (NULL, 1534252667, '::1', 'Logout')
有人能帮我吗有什么问题吗
提前感谢。当您编写
$this->session->sess_destroy()
在没有任何条件的情况下,检查“在其他之后写入”,它将在执行其他之前销毁会话与之类似
你喜欢这样吗
在控制器中
public function Logout() {
$return = $this->Login_model->saveLogout(); # alter
if(!$return)
{
echo "went wong"; die;
}
else
{
$this->session->sess_destroy();
redirect('Login');
}
}
在型号中
public function saveLogout() {
# your model code
return true; # add this
}
我认为您混淆了插入和更新。你可能想做一个或另一个,而不是两个。这是什么意思?我不明白你在说什么。你可以
在表中插入新行,或者用新值更新现有行。我对CodeIgniter不是很熟悉,但你似乎同时做了两件事:$this->db->insert()
然后$this->db->update()
好的,一开始我被你的代码弄糊涂了,我想你是在尝试插入和更新,对吗?一个用于记录act,一个用于更新用户记录?是的,确实如此,Alex你能检查这个问题并帮助我吗?我从过去几天一直在尝试,我不知道该怎么做。你能帮我吗?我可以问你一个疑问吗