Jump to content

Getting specific user from database?


Zero767

Recommended Posts

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!";
?>

Link to comment
Share on other sites

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.  :D

Link to comment
Share on other sites

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

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.