PDA

View Full Version : tracing user logins part 2


rattlsnak
10-03-2008, 11:23 PM
OK, I am using this code to insert a new row into a database everytime a user logs in so I can see who has logged in and when:

$inputuser = $_SESSION['username'];
$queryuser = "INSERT INTO userlogins (username) VALUES('$inputuser')";
mysql_query ($queryuser);

Have two fields in the database, username and a timestamp.

It works fine when a user logs in for the first time. Problem I just discovered, is if that same user logs in again, it will not add another new row. I understand why it wont update the previous row as I'm using an INSERT function and not an UPDATE, but why wouldnt it just keep adding new rows everytime someone logs in, whether a repeat user or not?

How do I correct this? I would prefer for it to simply add a new row everytime instead of updating the current row, or adding a count feature.

Thanks..

edbr
10-04-2008, 02:00 AM
im guessing because of not allowing unique names somewhere

rattlsnak
10-11-2008, 02:29 AM
OK, i added another field in the database and named it user id as a primary key and now it adds a new row everytime someone logs in no matter if a new user or repeat.

I have also found that using another UPDATE query will work as well:
$queryusers = "UPDATE userlogins (username) VALUES ('$inputuser')";
mysql_query ($queryusers);

That way, will add a new user, and update an existing one.