I hope you find and doing well, I would like to inform you that I am facing an issue with the created login system, as I'm not able to retrieve current logged in first_name from SQL database; as it's displaying only first record from the database if I logged in with any of the created users.
Here is the created function:
function user_data($user_id) {
$data = array();
$user_id = (int)$user_id;
$func_num_args = func_num_args();
$func_get_args = func_get_args();
if ($func_num_args > 1) {
unset($func_get_args[0]);
$conn = mysqli_connect('localhost', 'root', '', 'login_system') or die($connect_error);
$fields = '`' . implode('`, `', $func_get_args) . '`';
$data = mysqli_fetch_assoc(mysqli_query($conn, "SELECT $fields FROM `users` WHERE `user_id` = $user_id"));
}
return $data;
}
and here is the code to display the first name:
<div class="widget">
<h2>Hello, <?php echo $user_data['first_name']; ?>!</h2>
</div>
For example:
1) I have created the following users: alex, billy, Carlo.
2) While login with billy or Carlo usernames; I am only getting the first record details which are related to Alex.
Could you please check and advice if there is an issue in the code and why it's displaying only first record details.
Thank you.