php sessions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • truezplaya
    New Member
    • Jul 2007
    • 115

    php sessions

    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
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    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.

    Comment

    • truezplaya
      New Member
      • Jul 2007
      • 115

      #3
      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

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        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.

        Comment

        • truezplaya
          New Member
          • Jul 2007
          • 115

          #5
          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.

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, Truezplaya.

            You'll want to structure your SQL query something like this:
            [code=php]
            $_userid = (int) $_SESSION['userid'];
            $_postText = mysql_real_esca pe_string($_POS T['postText']);

            $__sql = "
            INSERT
            INTO
            `posts`
            SET
            `posterid` = '{$_userid}',
            `posttext` = '{$_postText}'" ;
            [/code]

            and so on.

            Comment

            • truezplaya
              New Member
              • Jul 2007
              • 115

              #7
              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

              Comment

              Working...