sql - Display data to Logged In User - PHP
I am creating a page that will display the login history. My code currently displays all logs and should only display the log history from the logged-in user.
Database -> Logs:
log_id | user_email | ip_address | time
-------+
LogHistory.php page:
{-code-2}
I have tried this code:
{-code-3}
With the above code I get this error message:
{-code-4}
Answer
Answer
Answer
Solution:
You just need to use parameters with prepared statements
<?php
$LoggedInUser = $_SESSION['user'];
$stmt = $dbh->prepare("SELECT * FROM Logs WHERE user_email = ? ORDER BY log_id ASC");
$stmt->execute([$LoggedInUser]);
if ($stmt->rowCount() == 0) {
echo 'Log history are empty.';
} else {
// Data we collected from the registered user
}
?>
Here live PHP code
Source