Hello so I have a logs table in my database and in every user action like log in, log out, edit, delete, create, I want it to be logged. Here is my current code in every action:
$action = "Log in"; //if user log in
$query = "INSERT INTO tbllogs
(logorigin,
logaction,
loguser,
logdate,
logoutcome)
VALUES
(:origin,
:action,
:user,
:dt,
:outcome)";
$stmt = $dbc->prepare($query);
$stmt->bindParam(':origin', $ip);
$stmt->bindParam(':action', $action);
$stmt->bindParam(':user', $_SESSION['id']);
$stmt->bindParam(':dt', $dateTime);
$stmt->bindParam(':outcome', $outcome);
$stmt->execute();
What I wanted to do is instead of repeating this code in every user action, I want to create a function that will do like this. But my problem is, I am using different values in my $action
variable like for example if the user will log in, $action = "Log in"
, if the user logs out, $action = "Log out"
. How can I accomplish that? Thank you!