-1
I need to create a script that records a last-accessed log in a table, but my Insert is not working. I created an Access class, where it logs in.
If anyone can help me. Thank you.
My class of access:
class Acesso {
public function run() {
$html = '';
Session::setValue('erro', '');
switch (App::getAction()) {
case 'logout':
$this->logout();
break;
case 'validar':
$this->validar();
break;
default:
$html = $this->login();
break;
}
return $html;
}
public function login() {
$html_login = new Html();
$html = $html_login->load('view/acesso.html');
return $html;
}
public function validar() {
$dados = Connection::select("SELECT login,senha,nome,departamento_id FROM users WHERE login='" . $_POST['usuario'] . "'");
Connection::close();
foreach ($dados as $reg):
if ($_POST['senha'] == $reg['senha']):
Session::setValue('logado', true);
Session::setValue('departamento', $reg['departamento_id']);
Session::setValue('nome', $reg['nome']);
else:
echo "<script>alert('Dados inválidos!'); location.href= 'index.php';</script>";
endif;
endforeach;
$sql = "update log set user_id= user_id, user_data= user_data where id=" . App::$key;
$dados = Connection::exec($sql);
header('Location: ' . URL);
}
public function logout() {
Session::setValue('logado', false);
header('Location: ' . URL);
}
}
When I run, you present this error below:
Fatal error: Call to a member function exec() on a non-object in
I don’t know if I understood you want to count how many times the user has logged in? or make a log table each time he logs in you save the date and time?
– user40905
How many times has the user logged in.
– Eduehi
Make a select to pick the value, saved in a variable and makes $variable +1
– user40905
I don’t know how to do it, you can give me an example?
– Eduehi
Try to be more specific, which isn’t working?
– Jorge B.
It does not save the record to the table, and displays this Fatal error: Call to a Member Function exec() on a non-object in
– Eduehi
$sql = "update
users
setacesso
=acesso
+ 1 Wherelogin
= '" . $_POST['user'] . "'"; $data2 = Connection::exec($sql);– Eduehi