Are you not storing the user id with the post? If you are then you just need to display the name associated with that id. The name (id) associated with a post should not have any dependency on whether a user is logged in.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
If the login name is the id for the user in the database, then that's fine to keep it in the session while they are logged in. You will still need to write that value to the database with the post though. The page that displays posts should retrieve the name of the poster along with the post from the database.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
I've tried setting the $loginuser name and session variables to the user id in the database. Obviously not the right thing to do.
Actually, I would store both the user name and the id in the session. Whatever statement that saves the post just needs to include the id. The query that shows posts just needs to display the name along side the comment, so pull all that info in a single query. If you are confused by that, post your code and we can figure out how to change it.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Still having problems with this...any ideas anyone?
Post the relevant code. Without that we can only speculate and offer generic suggestions.
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
Quick aside: Place code tags around code to maintain formatting. It really helps readability.
The part you'll need to change is
$insertSQL = sprintf("INSERT INTO messages (message) VALUES (%s)",
GetSQLValueString($_POST['textarea'], "text"));
I'm not certain how that table is structured, but you will need to add the user id something like this
$insertSQL = sprintf("INSERT INTO messages (userId, message) VALUES (%d,%s)", $userId, GetSQLValueString($_POST['textarea'], "text"));
$userId could be held in the session along with your other properties $_SESSION['userId']. You'll also need to make sure that the query which display the messages returns the user name along with the message and use that instead of the logged in user name from the session.
Does that clear it up a bit?
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
You will need to store the user id in the session when they log in and retrieve it as needed
$userId = $_SESSION['userId'];
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847