Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 updating two records

Author  Topic 

mastajbl
Starting Member

42 Posts

Posted - 2009-05-18 : 16:27:01
I have it set for a user to change their password upon first login, however because their link field is based on their access level i'm not sure how to define another update to change that field. Right now new user would be directed to change password page when they initially login. Than when they change their password i want them directed to a page based on their access level and update there link field for future logins.

<%

Username = Request.Cookies("userID")
Password = Request.Cookies("Password")
Response.Cookies("chgPassword")= Request.Form("Pass1")

if UserName<>"" then
if Password<>"" then
set conn = Server.CreateObject ("ADODB.Connection")
conn.Open Application("connString")
query = "SELECT [UserID], [Password], [Access] FROM Login WHERE UserID='" & UserName & "' AND Password='" & Password & "'"
set rs = conn.Execute (query)

' Check if the user and password are valid
if rs.eof then
' There is no record to match the UserName and Password
Response.Write "<p class=errmsg>Invalid user and password!</p>"
conn.Close
else
' User login ok and set the user_id value from the Members table in a session variable
Response.Cookies("userID") = rs("UserID")
rs.close
set rs = nothing

' Insert a new password in the login table with the password.
query = "UPDATE login SET Password = '" & Request.Cookies("chgPassword") & "' WHERE userID='" & UserName & "'"

query = "UPDATE login SET link = '" & Autoselect.asp & "' WHERE UserID='" & UserName & "' AND Access='" & All & "'"

query = "UPDATE login SET link = '" & chrspecs.asp & "' WHERE UserID='" & UserName & "' AND Access='" & CHR & "'"

query = "UPDATE login SET link = '" & gmspecs.asp & "' WHERE UserID='" & UserName & "' AND Access='" & GM & "'"

query = "UPDATE login SET link = '" & fordspecs.asp & "' WHERE UserID='" & UserName & "' AND Access='" & FORD & "'"

conn.Execute (query)

conn.close
set conn = nothing

Response.Redirect "newlogin.html"
end if
else
Response.Write "<p class=errmsg>Please fill both fields.</p>"
end if
end if

%>

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2009-05-18 : 16:42:14
you cannot execute both statements with same variable. When you assign the value to parameter "query" second time, its overwritten. Use a stored procedure instead and put both your UPDATEs in it.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page
   

- Advertisement -