dirty_student Posted March 10, 2006 Share Posted March 10, 2006 Hi All,Hope somebody can help... the problem is that i have created a log in page for my site using dreamweaver MX and php mysql everything works fine but i would like to display the firstname and surname of the user that has logged in on the next page. My database is set up that the username and password fields are in the same table as the data i want to display if you willStudent_NumberUser_NamePasswordSurname First_Nameif you can understand what i mean i would appriciate some help!!!! Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 10, 2006 Share Posted March 10, 2006 welcome to the forums! hope we can help you out here.if i understand what you're after, once someone successfully logs it, you ought to keep a session variable with their user_id (or even just their username) so that you can pull their information on any future pages they hit. once you do that, you can run a simple query at the top of the page pulling their information from the database. use it wherever you want on the rest of the page. Quote Link to comment Share on other sites More sharing options...
dirty_student Posted March 10, 2006 Author Share Posted March 10, 2006 yeah that sounds about right but how do i create the session can you explain? sry complete novicesteve Quote Link to comment Share on other sites More sharing options...
craygo Posted March 10, 2006 Share Posted March 10, 2006 Well first off every page in your site needs to start with session_start();Even the login page. After they fill in there username and password, and are authenticated you store the username in a session. Here is some code I use once the user has entered his info[code]if(isset($_POST['username'])){$username = $_POST['username'];$password = md5($_POST['password']);$getuser = "SELECT * from users WHERE username = '$username' AND password = '$password'"; $result = mysql_query($getuser) or die (mysql_error()); $r = mysql_fetch_array($result); $qualify = mysql_num_rows($result);if($qualify > 0){$_SESSION['username'] = $_POST['username'];}[/code]Now whenever you want to use the persons username you just reference the session id[code] echo "Hello $_SESSION['username'] welcome to my site";[/code]Ray Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.