|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#16
|
|||
|
|||
|
Hello Shadow,
I have a few questions. Do i need to do anything with the strURL= ""? I don't need to include a URL do I? Also, I'm guessing that strUserName = oRS("username") and strDeptName = oRS("DeptName"), are linked to the database based on names ? I feel I should apologise for the lack of knowledge. Regards MG |
|
#17
|
|||
|
|||
|
Hi Shadow, for some reason the following error message appears, but i cant understand why this might be?
Microsoft OLE DB Provider for SQL Server (0x80040E10) Procedure or function 'spGetUserDetailsByID' expects parameter '@iUserID', which was not supplied. C:\INETPUB\WWWROOT\INTRANET\ADMIN\STORES\../../i/security.asp, line 103 line 103 is highlighted in red Code:
sSQL = "exec spGetUserDetailsByID " & iuserID
SET oRS = oDB.Execute(sSQL)
strUserName = oRS("username")
strDeptName = oRS("departmentName")
strURL = ""
If strDeptName="IT" And strUserName="Joe bloggs" Then
strURL = "page1.asp"
ElseIf strDeptName="IT" And strUserName="Brian bloggs" Then
strURL = "page2.asp"
ElseIf strDeptName="IT" And strUserName="Claire bloggs" Then
strURL = "page3.asp"
End If
oRS.Close
If Len(strURL)>0 Then
Response.Redirect(strURL)
End If
Im sure im doing the same as the other parts of my code Kind regards MG Quote:
|
|
#18
|
||||
|
||||
|
Quote:
oRS("username") and oRS("DeptName") will both give you value from your database, and that in the code is being stored inside something known as Recordset, which is what executing Stored Procedure returns. regarding that error, change those two lines: Code:
sSQL = "exec spGetUserDetailsByID " & iuserID SET oRS = oDB.Execute(sSQL) to this instead: Code:
sSQL = "exec spGetUserDetailsByID " & iuserID
Response.Write("sql: " & sSQL & "<br />")
Response.END()
SET oRS = oDB.Execute(sSQL)
and post here what you get. (need to debug and see the SQL being executed) |
|
#19
|
|||
|
|||
|
Hello,
Ok, so i did what you asked and i get the following returned, with my name at the front: Mind_grapes sql: exec spGetUserDetailsByID Hope this is helpful? Kind regards MG Last edited by mind_grapes : October 20th, 2009 at 08:50 AM. |
|
#20
|
||||
|
||||
|
it means you do not supply any user ID.
in post #13 you have code with variable called "iuserID", I assumed you already have there valid ID of some user. I see now that I was wrong. what is this code? just some code you copied from somewhere? anyhow, that variable must contain valid ID of user, for exampe if you will add this line to your code: Code:
iuserID = 3 it will assign value of 3 to the variable, then the value 3 will be passed to your stored procedure, that will go and look for user with that ID. (meaning record from the table tblUsers where the field userID has value of 3) Sorry for the confusion, sometimes I assume too much. ![]() |
|
#21
|
|||
|
|||
|
Hello Shadow, thank you for the reply.
I think its my fault. If you have assumed something its probably because i have not included nor supplied the correct information you need. So it is my fault for not being clear, i apologise for that. I have just checked post 13 and can see to what you are referring. You're right i need to get the users ID first and then assign that value to pass to the stored procedure. But I just don't know how to do this. I had this code to get the persons name: Code:
userNameTest = Mid(request.ServerVariables("AUTH_USER"), InStr(request.ServerVariables("AUTH_USER"), "\")+1)
response.write(userNameTest & " ")
But I'm guessing this is not the best way to go about doing this? I did try to get a stored procedure to return the users ID and assign it to a variable, but i couldnt get it to work, so then tried to use the person name. Once I had done all that it brought me here, to this point, trying to redirect people. The userID is held in a database against names dept etc. is this possible?: Code:
iUserID = <%=Session("LOGGED_ON_USER_ARRAY")(4) %>
To get the users ID Regards MG |
|
#22
|
||||
|
||||
|
sorry, but you need to decide how to take user ID.
the ServerVariables("AUTH_USER") hold the account name, not ID so that won't help you. if you already have the ID in ession("LOGGED_ON_USER_ARRAY") then yes, it would work. but correct ASP syntax is: Code:
<%
iUserID = Session("LOGGED_ON_USER_ARRAY")(4)
%>
I see you lack the most basic knowledge in the ASP syntax, maybe you better learn those basics from books or online tutorials like w3schools - when you have better grasp of things like ASP delimeters, ASP variables and the basic syntax you will find it easier to write "real" ASP code. ![]() |
|
#23
|
|||
|
|||
|
Hi Shadow, sorry for the slow reply i've not been at work due to an illness, back back now.
Thanks for the info. I believe my manager had set that already, i think its in the global.asa file. the code is Code:
sub Application_OnStart
' Application("CONN_STRING") = "Driver={SQLServer};Server=ITFolder;Database=intran et; Uid=INTRANET;Pwd=pswrd;"
Application("DEFAULT_URL") = "http://localhost"
Application("CURRENT_USERS") = 0
Application("ADMIN_MESSAGE") = 0
SET Application("oDBConn") = Server.CreateObject("ADODB.Connection")
Application("oDBConn").open(Application("CONN_STRING"))
end sub
sub Application_OnEnd
'some code
end sub
sub Session_OnStart
Session("TEST_VARIABLE") = ""
Session("DEBUG_MODE_ON") = False
Session("LOGGED_ON_USER_ARRAY") = Split(Request.ServerVariables("LOGON_USER"), "\")
'this was done by me (psk) when tyring to create the security settings.
'Security Levels
'Session("AccessLevel") = oRS ("UserAccessLevel")
'Session ("nAccessLevel") = CLng(Session("LOGGED_ON_USER_ARRAY").Fields("UserAccessLevel").Value)
SET Session("LOGGED_ON_USER_ARRAY") = Application("oDBConn").Execute("EXEC spGetUserDetails '" & Right(Request.ServerVariables("LOGON_USER"), LEN(Request.ServerVariables("LOGON_USER")) - INSTR(Request.ServerVariables("LOGON_USER"),"\")) & "'")
Application("CURRENT_USERS") = Application("CURRENT_USERS") + 1
end sub
sub Session_OnEnd
Application("CURRENT_USERS") = Application("CURRENT_USERS") - 1
'some code
end sub
Have I read it right? I admit im not the best, i do know little things but seem to forget them all the time, still sturggling i guess. i think you're right its best i go over the basics again because i do feel so rusty. Sorry once again.Kind regards MG Last edited by mind_grapes : October 23rd, 2009 at 05:47 AM. |
|
#24
|
||||
|
||||
|
that's OK mate, you don't have to apologize.
![]() anyhow that session variable indeed hold what you need. to know once and for all, please have the following code in your page: Code:
<%
Dim oUserRS, x
Set oUserRS = Session("LOGGED_ON_USER_ARRAY")
For x=0 To oUserRS.Fields.Count-1
Response.Write("field name: " & oUserRS.Fields(x).Name & ", value: " & oUserRS(x) & "<br />")
Next
%>
what is the output of this code? once you know I believe this thread can finally come to final peace and solution. ![]() |
|
#25
|
|||
|
|||
|
Hello Shadow, thank you for the reply.
I shall add this to the security.asp page and post back what i can see. Kind regards MG |
|
#26
|
|||
|
|||
|
Hi shadow,
This line of code did bring back the UserID, so that was good. Code:
iuserID = Session("LOGGED_ON_USER_ARRAY")(4)
The lines of code you asked me to include brought this information back: field name: departmentName, value: Business Systems field name: username, value: Mind_grapes field name: , value: Mind_grapes field name: FolderName, value: BUSSYS field name: userID, value: 2 field name: departmentID, value: 1 field name: StoreID, value: Brilliant, this is all the data that is currently in the database, thats good news right Regards MG Last edited by mind_grapes : October 26th, 2009 at 10:40 AM. |
|
#27
|
|||
|
|||
|
Hi Shadow, I just thought I'd update you on what I've been doing.
I have been playing around with the code and going back over what you've suggested on this topic. It seems to be working now, so thank you for that. I have added extra tables and columns to the Stored Procedure so I now need to work on the new data too, and incorporate these feilds when redirecting people to the correct pages. But with what you have recommended I think it should all work out. Will check back later once done. Thank you for everything you have done. Its appreciated a great deal and a massive help in my learning. Kind regards MG |
|
#28
|
||||
|
||||
|
no problem MG, I'm really glad I could help.
![]() one little suggestion though, in your code change this one: Code:
Session("LOGGED_ON_USER_ARRAY")(4)
to this instead: Code:
Session("LOGGED_ON_USER_ARRAY")("userID")
the reason is that when you give number, you rely on the field to always be in that specific index... if you change the SQL statement bringing this field back the index might change and the code will break. when using the field name it doesn't matter where it appears in the SQL statement, it will always find it - more safe, less room for future problems. |
|
#29
|
|||
|
|||
|
Hi Shadow, thanks for the reply.
I will update as you have suggested, thank you once again. I've been playing around with the code and also going over some VBScript tutorials, will go over ASP again soon too. My updated Stored Procedure now looks like this: Code:
SELECT storeNumber ,storeName ,userID ,username ,FirstName + ' ' + LastName ,departmentID ,departmentName ,FolderName ,roleID ,roleName ,levelID ,levelName ,levelCode ,fk_storeID as StoreID FROM tblUsers u LEFT JOIN tblUser2Dept AS u2d on u.userID = u2d.fk_userID LEFT JOIN tblDepartment AS d on u2d.fk_deptID = d.departmentID LEFT JOIN tblUser2Store AS u2s on userID = u2s.fk_userID LEFT JOIN tblUser2Role AS u2r on u.userID = u2r.fk_userID LEFT JOIN tblRoles AS r on u2r.fk_roleID = r.roleID LEFT JOIN tblStores AS s on u2s.fk_storeID = s.storeID LEFT JOIN tblSA2AccessLevels AS sa2al on r.roleID = sa2al.fk_roleID AND d.departmentID = sa2al.fk_deptID LEFT JOIN tblLevels AS l on l.levelID = sa2al.fk_levelID WHERE userID = @iUserID END And I have added to your code and it now looks like this: Code:
strStoreID = oRS("StoreID")
strStoreNumber = oRS("storeNumber")
strStoreName = oRS("storeName")
strUserName = oRS("username")
'strFullName = oRS("FirstName + ' ' + LastName")
strDepartmentID = oRS("departmentID")
strDeptName = oRS("departmentName")
strFolderName = oRS("FolderName")
strRoleID = oRS("roleID")
strRoleName = oRS("roleName")
strLevelID = oRS("levelID")
strLevelName = oRS("levelName")
strLevelCode = oRS("levelCode")
strURL = ""
I would guess this is right as the link to the database is made and the variables are being assigned to a column header? With the VBscript amended all should be done with the rediretcing of people to the correct pages. Kind regards MG Quote:
Last edited by mind_grapes : October 29th, 2009 at 09:53 AM. |
|
#30
|
|||
|
|||
|
Hi Shadow,
Sorry, meant to ask, do you mean to change it where i set the userID, or in the main section where session is defined? Regards MG |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > VBScript - Database - General - Can you assign the select result of a stored procedure as a value? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|