By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,641 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,641 IT Pros & Developers. It's quick & easy.

php sessions

100+
P: 115
I am creating a forum and i have session running. The session displays the user name in the posts. This is all dandy and i have the user name displaying but the problem is that every time someone else logs in all the user names in the posts change!!!! I am gathering i have to save these somewhere but i have no idea how ? can anyone help?

I have looked at this problem another way but i just keep confusing myself. I have an id attribute in both messages and members table. So i was thinking using the session to store the id and then do a link(in mysql) to get the user name but i keep failing miserably

I would post the code up but it is an assignment i am happy to send it via e-mail so i can log it which would give me backup in case i needed to prove it is my own work.

cheers in advanced
Dec 24 '07 #1
Share this Question
Share on Google+
6 Replies


pbmods
Expert 5K+
P: 5,821
Heya, truezplaya.

Since there is a one-to-one relationship between posts and authors in this context, your best bet would be to store the author ID in the messages table.
Dec 24 '07 #2

100+
P: 115
Hey cheers for clearing that point up but how would i get the id from members table which is automatically incremented to save in the messages table? The only way i can think is to let the user pick their own user id and every message they send they have to type that in.

You might gather that i am pretty new to this lol

cheers
Dec 24 '07 #3

pbmods
Expert 5K+
P: 5,821
Heya, truezplaya.

Don't worry. We've all been there before.

When the User logs in, you'll want to store his member ID in the $_SESSION.

Then, when the User creates a post, you can retrieve his member ID and save it with the post data.
Dec 24 '07 #4

100+
P: 115
It is the saving part that i am unsure of!!!!!!!! It's getting to the stage i just feel like throwing my comp out of the window arrrrggggg.
Dec 25 '07 #5

pbmods
Expert 5K+
P: 5,821
Heya, Truezplaya.

You'll want to structure your SQL query something like this:
Expand|Select|Wrap|Line Numbers
  1. $_userid = (int) $_SESSION['userid'];
  2. $_postText = mysql_real_escape_string($_POST['postText']);
  3.  
  4. $__sql = "
  5. INSERT
  6.     INTO
  7.         `posts`
  8.     SET
  9.         `posterid` = '{$_userid}',
  10.         `posttext` = '{$_postText}'";
  11.  
and so on.
Dec 25 '07 #6

100+
P: 115
Thank you very much sorry it has taken a while to reply i have just been making sooooo much progress after getting stopped in my tracks for a while !!!!!!!!

Truez
Jan 17 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.