For the user who is logged in
Now lets get started Most login script use the variable username ( some use userNAME )
This is made when the user logs in so we know whos who
it looks a bit like this
$username
Now first thing we got to do is start the session and connect to the database
session_start();
mysql_connect("host", "username", "password") or die(mysql_error());
mysql_select_db("database name") or die(mysql_error())
The my sql username and password you make / get when you make a new database
Now we query the database about the column we want and which table its in
$sql = "SELECT username from users WHERE username='".$_SESSION['username']."';";
$res = mysql_query($sql) or die('Invalid query: ' . mysql_error());
$val = mysql_fetch_array($res);
line 1...now we are telling it to select the username column from the database from the users table
The were bit is telling it to only show the username of the person logged in
if we have set the $username ( which most login script do )
line 2...Then we tell it that if there is a error with any off it to show a error messege
Line3 is just telling it to fetch the info we want ( the username in this case)
now we display the username on the page by echoing it out
echo $val['username'];
so now here is the code in fill
mysql_connect("host", "username", "password") or die(mysql_error());
mysql_select_db("database name") or die(mysql_error())
$sql = "SELECT username from users WHERE username='".$_SESSION['username']."';";
$res = mysql_query($sql) or die('Invalid query: ' . mysql_error());
$val = mysql_fetch_array($res);
echo $val['username'];
You can do this with other stuff has well not just username's e.g gender email address anything that is being stored





MultiQuote




|