How do I fetch user details to profile page using PDO?

All you’re doing there is assigning a string containing ['email'] to that session variable. I suspect you want to retrieve the email address from the database and put it in there. After you have fetched the value from the query in login.php, I think you need something like

$_SESSION['email'] = $fetch['email'];

Of course, you could just use the email address that the user typed into the form, as long as you do that after you have run the query to check that it’s valid and that the password matches, and not right at the start of the code where you have it.

? placeholders in queries only have their special meaning inside those queries.

Perhaps you could post the updated versions of the code - not just snippets and individual lines - so that people can comment on where you are assigning and checking the values.

1 Like