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
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 ?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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  :)

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.