Unholy Prayer Posted August 2, 2006 Share Posted August 2, 2006 Ok, I made my register, login, and logout scripts, but the last thing i need to know is once a user is logged in, how do I display their username? For example, if Bob logs in under the username Bob, how do I make it say "Welcome, Bob." But then it should change for every user. If the user Henry logs in from a different computer, it should display "Welcome, Henry", not "Welcome, Bob". Can someone help me with this? Quote Link to comment Share on other sites More sharing options...
sw0o0sh Posted August 2, 2006 Share Posted August 2, 2006 If there name is represented by a variable, why not echo the variable.. ? Quote Link to comment Share on other sites More sharing options...
mastermike707 Posted August 2, 2006 Share Posted August 2, 2006 Just echo whatever variable contains the user's username where u want their name. Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted August 2, 2006 Author Share Posted August 2, 2006 Will the session scripting find the username of the person that is logged in? If so, all I have to do is use <?php echo "Welcome, $username"; ?> ? Quote Link to comment Share on other sites More sharing options...
sw0o0sh Posted August 2, 2006 Share Posted August 2, 2006 [quote author=Unholy Prayer link=topic=102687.msg407927#msg407927 date=1154508069]Will the session scripting find the username of the person that is logged in? If so, all I have to do is use <?php echo "Welcome, $username"; ?> ?[/quote]Or make sure you set the variable so it can be found, I'm not to crazy on php but did you try anything like,[code]<?php$username=$_REQUEST["username"];echo "Welcome, $username";?>[/code]?? Quote Link to comment Share on other sites More sharing options...
nethnet Posted August 2, 2006 Share Posted August 2, 2006 When you query the database in your login script, just pull out the username and set it to a session variable (assuming you are using sessions).Your code should look something like this:[code]<?phpsession_start();$username = $_POST['username'];$password = $_POST['password'];$query = mysql_query("SELECT * FROM table WHERE username='$username' AND password='$password' LIMIT 1");if (mysql_num_rows($query) == 0){ echo "<strong>Invalid username/password</strong>"; exit();}$assoc = mysel_fetch_assoc[$query];$_SESSION['username'] = $assoc['username'];echo "<strong>Welcome, {$_SESSION['username']}!</strong>";?>[/code]Hope this helps Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted August 2, 2006 Author Share Posted August 2, 2006 I tried the code you gave me, but I got an error on the following line:[code]$assoc = mysel_fetch_assoc[$query];[/code]The error was:[quote]Parse error: syntax error, unexpected '[' in /home/mutantde/public_html/bbultimate/functions.php on line 16[/quote] Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted August 2, 2006 Share Posted August 2, 2006 the line [code]$assoc = mysel_fetch_assoc[$query];[/code]should be [code]$assoc = mysql_fetch_assoc[$query];[/code] Quote Link to comment Share on other sites More sharing options...
Unholy Prayer Posted August 2, 2006 Author Share Posted August 2, 2006 Hmm... I changed it, but I still get the same error on the same line. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 2, 2006 Share Posted August 2, 2006 You'll want to use parenthesesis - () and not sqaure brackets []:$assoc = mysql_fetch_assoc($query); Quote Link to comment Share on other sites More sharing options...
nethnet Posted August 2, 2006 Share Posted August 2, 2006 Whoops, simple typo. Sorry about that. Quote Link to comment Share on other sites More sharing options...
legohead6 Posted August 2, 2006 Share Posted August 2, 2006 [quote author=Unholy Prayer link=topic=102687.msg407927#msg407927 date=1154508069]Will the session scripting find the username of the person that is logged in? If so, all I have to do is use <?php echo "Welcome, $username"; ?> ?[/quote]the seesion is stored on the users computer not the web server..so unless there both on a wierd screwed up busness network it will find correctly... 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.