Forum Moderators: coopster

Message Too Old, No Replies

How do I display the current user?

have basic user admin via php/mysql users table

         

mbatta

4:26 am on Jan 23, 2005 (gmt 0)

10+ Year Member



when a user posts a message to my site, how do I save that user's name to the meassage table to disply next tot eh message? (mysql users table)
Also, how do I just display the user on the page like at the top of this site?

mb

dmmh

7:56 am on Jan 23, 2005 (gmt 0)

10+ Year Member



1: make a column in the message post table containig user id's, this will hold the user's id from the user table, so you can query that table to see who posted it.
INNER JOIN query would be handy here btw

2: upon logging in register a session variable which contains the user's name. like:

if (mysql_num_rows($result) == 1) //if the number of results equals 1 (eg.: user entered correct details to login)
{
// if they are in the database register some stuff we need across the site
$_SESSION['valid_user'] = $row['username']; // <-----------
$_SESSION['uid'] = $row['uid'];// user id, probably your first column in the user tabel
}

next just do a echo $_SESSION['valid_user'] where you want to display the name of the current logged in user

mbatta

1:54 pm on Jan 23, 2005 (gmt 0)

10+ Year Member



thanks, but due to my ignorance i need a little more clarification.

1: make a column in the message post table containig user id's, this will hold the user's id from the user table, so you can query that table to see who posted it.

>Im ok here

INNER JOIN query would be handy here btw

>OK

2: upon logging in register a session variable which contains the user's name. like:

if (mysql_num_rows($result) == 1) //if the number of results equals 1 (eg.: user entered correct details to login)
{

>what is "mysql_num_rows"?

// if they are in the database register some stuff we need across the site
$_SESSION['valid_user'] = $row['username']; // <-----------
$_SESSION['uid'] = $row['uid'];// user id, probably your first column in the user tabel
}
>which part of above is grabbing the current user from the client side? I assume from the server side there can be many users logged in at the same time....my guess here is its the 'valid_user'?

next just do a echo $_SESSION['valid_user'] where you want to display the name of the current logged in user

jatar_k

7:15 pm on Jan 24, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sounds about right