Jump to content

Retrieving user information via session.


nano

Recommended Posts

Hey,

 

I have tried to search but I found it hard as I am not sure what I am searching  :D

 

Just a quickie really - If I have created a session from the login

 

$_SESSION['email']

 

It is obvisouly checking the user table at the login page.

 

If I wanted to then have a members page that lists all of the users details, how would I go about this?

 

Could I for example do:

 

<?php
include("database/database.php");

$id=$_SESSION['email'];
$row = mysql_fetch_array(mysql_query("select * from user_system WHERE email = $id"));
?>

 

Then print the information like:

 

{$row['email']}

 

I have had a play but can't get it working, any help would be appreciated. Cheers.

Link to comment
https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/
Share on other sites

Okay lets try fetching object instead array...

<?php
include("database/database.php");

$id= $_SESSION['email'];
$row = mysql_fetch_object(mysql_query("select * from user_system WHERE email = $id"));
?>

 

You would echo information like this...

<? echo "$row->email"; ?>

or

Your email: <?= $row->email ?>

Yeah thanks, problem is the code looks fine to me but it still doesn't seem to work.

 

I have run simular code on different pages and it works perfect  :-\

 

<?php
session_start();

if (!isset($_SESSION['email'])){
    header("Location:login.php");
    exit();
}

include("database/database.php");

$user = $_SESSION['email'];
$info = mysql_fetch_object(mysql_query("select * from user_system WHERE email = $user"));

?>

 

<a href='account.php' class='toollink'><? echo "$info->email"; ?></a>

 

No errors, just nothing.. I also can't print or echo $info - not sure if that is normal.

 

Thanks

Ok I found the problem, and for anyone else who might have a simular issue:

 

The variables in the SQL statement have to be in quotes, otherwise it will treat the '@' as a like argument (from the email address)

 

so result:

 

$info = mysql_fetch_array(mysql_query("select * from user_system WHERE email = '$user'"));

 

and to echo:

 

{$info['email']}

 

Thanks for the help  :)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.