Update last login date

They have: 105 posts

Joined: Mar 2006

I have a field in my users table called lastlogin with datatype date,

I want this field to be updated with the time and date everytime the user logs in but I can't get the following SQL query in the process login.asp to work

SQLtemp = "SELECT * FROM password WHERE user = '" & Request.form("login") & "' AND UPDATE lastlogin ='date'"

Set rs = Apples.Execute(SQLtemp)

He has: 1,380 posts

Joined: Feb 2002

This is an easy answer!

When they login, process a small script that just sends an UPDATE query to the user's info and sets "lastlogin" to the current date. But only run this on every login, and then it will be a "last login" for sure.

It should look something like:

UPDATE password WHERE user = '[userid]' SET lastlogin = '[date_variable]'
'

They have: 105 posts

Joined: Mar 2006

I can get this to work

SQLtemp = "SELECT * FROM password WHERE user = '" & Request.form("login") & "' AND UPDATE password WHERE user = '" & Request.form("login") & "' SET lastlogin = 'date'"

Set rs = Apples.Execute(SQLtemp)

I have tried the above but get a syntax error and I have also tried the following:

SQLtemp = "SELECT * FROM password WHERE user = '" & Request.form("login") & "'

LAST LOGIN = "UPDATE password WHERE user = '" & Request.form("login") & "' SET lastlogin = 'date'"

Set rs = Apples.Execute(SQLtemp)
Set rs = Apples.Execute(LASTLOGIN)

I'm really not sure how to do this and it should be simple! If it was in PHP I could prob do it!

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Drew wrote: LAST LOGIN = "UPDATE password WHERE user = '" & Request.form("login") & "' SET lastlogin = 'date'"'
Set rs = Apples.Execute(LASTLOGIN)'

LAST LOGIN Vs. LASTLOGIN notice the space in the variable name. Also, good for debugging, if you need to know what SQL is being passed to MySQL just do:

' DEBUG
Response.Write(LASTLOGIN)
' END DEBUG
'

By the way, all uppercase variable names are usually reserved for constants, you might wish to rename that LastLogin (or something similar). Just good programming practice. Smiling

Drew wrote: If it was in PHP I could prob do it!

It probably doesn't make much difference in this case as all you're doing is passing SQL to MySQL. Smiling

a Padded Cell our articles site!

He has: 1,380 posts

Joined: Feb 2002

Also, if I were you, I would pull the username and password and stuff out FIRST and then filter it, store it in a variable... and then use that variable in the SQL rather than "Request.form(....", just for coding's sake.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.