nano Posted March 1, 2008 Share Posted March 1, 2008 Hey, I have tried to search but I found it hard as I am not sure what I am searching 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 More sharing options...
shocker-z Posted March 1, 2008 Share Posted March 1, 2008 you need session_start(); at the top of yopu page where you create $_SESSION['email'] and every page you wish to carry it over to. see http://uk.php.net/manual/en/function.session-start.php Regards Liam Link to comment https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481078 Share on other sites More sharing options...
nano Posted March 1, 2008 Author Share Posted March 1, 2008 Yeah I have session_start(); my question was probably a little messy Just once a user has logged in correctly, how can I display all of their information. Cheers. Link to comment https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481081 Share on other sites More sharing options...
ILYAS415 Posted March 1, 2008 Share Posted March 1, 2008 how did u try to echo your information? plz show the script =) Link to comment https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481083 Share on other sites More sharing options...
nano Posted March 1, 2008 Author Share Posted March 1, 2008 That is my question, I think.. I want to know how to echo the details of the user table after a user has logged in Link to comment https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481086 Share on other sites More sharing options...
QuietWhistler Posted March 1, 2008 Share Posted March 1, 2008 Why don't you just use: print( $row[ "email" ] ); etc? Simple as that right? Link to comment https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481088 Share on other sites More sharing options...
ILYAS415 Posted March 1, 2008 Share Posted March 1, 2008 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 https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481090 Share on other sites More sharing options...
nano Posted March 1, 2008 Author Share Posted March 1, 2008 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 https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481164 Share on other sites More sharing options...
nano Posted March 1, 2008 Author Share Posted March 1, 2008 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 https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481227 Share on other sites More sharing options...
ILYAS415 Posted March 2, 2008 Share Posted March 2, 2008 lool didnt se that it was sooo obvious Link to comment https://forums.phpfreaks.com/topic/93891-retrieving-user-information-via-session/#findComment-481238 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.