Zero767 Posted March 30, 2007 Share Posted March 30, 2007 Hey, I have my login script, and I have it setup so that if they are not logged in it shows the login box, and if they are, it shows a welcome message. But how I can I get the specific username of the person who logged in, from the database? Here is my code: <?php if (!isset($_SESSION['authenticated'])) { echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"\"> <label for=\"username\">Username:</label> <input type=\"text\" name=\"username\" id=\"username\" /> <label for=\"textfield\">Password</label> <input type=\"password\" name=\"pwd\" id=\"pwd\" /> <input name=\"login\" type=\"image\" src=\"images/login_button.jpg\" id=\"login\" value=\"Log in\" /> </form>"; exit; } echo "Hey, welcome back $username!"; ?> Quote Link to comment Share on other sites More sharing options...
Zero767 Posted March 30, 2007 Author Share Posted March 30, 2007 Ok, I figured out how to put the name there. But, when I code it so they can change details about themselves, how to I know which user specificly is logged in? Do I match the superglobal array I made for my session to match the username with the one in the databse then do an if statment from there? Thanks. Quote Link to comment Share on other sites More sharing options...
Lytheum Posted March 30, 2007 Share Posted March 30, 2007 Yes - when they login, you give them a username session, then in your change details page you would - session_start(); $username = $_SESSION['username']; $sql = "SELECT * FROM table WHERE username = '$username'"; $result = mysql_query($result); 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.