Hi every one.
I'm Doing a web site using PHP and SQL.
I have a DB for Usernames and Passwords and when a User logs in It has to say Hi Username.
I was wandering how do I get the User name After the log in.
Is there a scrit that has to be in the Log in Page or a Query on the Page after?
Thanks
Login
Moderator: General Moderators
- moiseszaragoza
- Forum Commoner
- Posts: 87
- Joined: Sun Oct 03, 2004 4:04 pm
- Location: Ft lauderdale
- Contact:
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
This is assuming once logged in their username is set in a session and assuming their username is stored in the `usersname` field.
Code: Select all
<?
$query = "SELECT * FROM `users` WHERE `usersname`='".$_SESSION['username']."'";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_assoc($result);
echo 'Hello '. $row['username'];
?>
Last edited by John Cartwright on Sun Oct 03, 2004 4:15 pm, edited 1 time in total.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you can store the username in a session variable, cookie, or just query for it on every page. Depends on what kind of infrastructure you want to work with. Personally, I query for it on every page. Because all their user information could change from one page to the next. especially their access privledges.