OK guys Maybe my first question was not very clear, sorry for that. So here’s my problem. Situation: MySql Database contains: Username, Password & UserID When the user logs in, their username is checked by the session and registered in the session variable. But I think this is captured from the text field when they login. When the user makes a comment or other interaction with the site, their user name is logged from the session with the comment. I would also like to have their UserID logged from the MySql Database. How can I do this? Thanks in advance
Well, I'm a little unclear about what you're asking but I'll give it a shot. You can create a new table with two fields, userid / log. Insert the users latest action in the log. So, for example if someone posts a comment, do something like.. // make sure to make the mysql connections first. mysql_query("INSERT INTO UserLogs (id, log) VALUES ('$useridvar', 'Posted Comment')"); PHP: If you mean you want to have a user verified through MySQL with their password and username, then try this; $user = $_SESSION['userid']; $pass = $_SESSION['pass']; // make sure to make the mysql connections first. $result = mysql_query("SELECT * FROM users WHERE id = '$user' AND password = '$pass'"); if (mysql_num_rows($result) == 0){ echo 'Invalid User.'; } PHP:
Triggs First off, thanks for responding, it’s much appreciated. What I really need, to capture, is the UserID. This is stored in the MySql user database. When they register, it is created then. It stays there and the user has no interaction with it. So they never type it, or even know it. I need it to be available to the session so that my system can capture it as they interact with the site. I think it needs to be done with something like: SELECT userid FROM user DB, WHERE username = $username Then I need some way of capturing it. Is this clearer? Sorry for the confusion. Thanks
Oh, yes. session_start(); // make sure to do mysql connections and such before this $result = mysql_query("SELECT * FROM users WHERE username = '$username'"); $_SESSION['userid'] = $result['userid']; PHP: Hope this is what you wanted.
I always includes UserID along w/ some other important stuffs like real IP, timestamp, on sessions, instead of actual usernames (considering you set the username as candidate key on your table). that is why u have primary key (UserID)on your tables, it represent the entire row
Thanks Triggs I'm trying to get my head around this a bit more. The code you gave looks like it will probable work. I just need to find out where to put it. I'm using a login system that has lots of files used to make it work and it is also object oriented. I'm gonna give it a try now and I'll get back to you to let you know how I went. cheers