I'm trying to create a log table for my DB that register all the actions that happen, and I was thinking of creating one log table for each table so I'll be able to read the information easily.
But I'm not sure how to do it because I want the input of the log table to a variable where I'll format the text and put the other variables to register the input.
Eg: $log = '[' . $data_log . '] ' . ' The item '. $ativo .' with the S/N '. $numero_serie .' was delivered to the employee '. $id_colaborador);
And for the DB I have this, I know it's wrong but I don't know why..
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$acao_log2 = '[' . $data_log . '] ' . ' O ativo '. $ativo .' com o S/N '. $numero_serie .' foi entregue ao colaborador '. $id_colaborador . ' [' . $user . ']' ;
$sql = "INSERT INTO ativos (ativo,comentario,data_aquisicao,localizacao,fabricante,modelo,imei,
numero_serie,ativo_sap,evento,data_evento,id_colaborador)
SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, id_colaborador
FROM colaboradores
WHERE nome = ?";
$log = "INSERT INTO log_ativos (acao_log, data_log, id_ativo)
VALUES (". $acao_log2 . "," . $data_log . ", id_ativo = id_ativo WHERE id_ativo = ?";
$q = $pdo->prepare($sql);
$qlog = $pdo->prepare($log);
$q->execute(array($ativo,$comentario,$data_aquisicao,$localizacao,$fabricante,$modelo,$imei,$numero_serie,$ativo_sap,$evento,$data_evento,$id_colaborador));
$qlog->execute(array($acao_log,$data_log,$id_ativo));
Database::disconnect();
The thing is, I dont want the user to input nothing for the logs, it should be automatic :/
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\gestao\Ativos\create.php:129 Stack trace: #0 C:\xampp\htdocs\gestao\Ativos\create.php(129): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\gestao\Ativos\create.php on line 129