Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

query db from username 1

Status
Not open for further replies.

tamnet

IS-IT--Management
Jun 2, 2005
31
GB
I am usin g the following code to get the username when users load the home page on our intranet.
Code:
<% '***Start Function ValImage
ValImage = (ucase(Request.ServerVariables("LOGON_USER")))
ValImage = Replace(ValImage, "SOMEWHERE-UK\","")
'***End Function ValImage
%>

I then have a hidden field where i store the value of ValImage like so

Code:
<input name="hidName" type="hidden" id="hidName" value="<%=ValImage%>">

The page has 2 tables in it and the tables have links to other pages, the first table has 6 links and the second table 4 links. and I want to show either of the tables dependent on whether the username is stored in a DB table or not i.e

IF username exists then
show table 1
Else
Show table 2

Could someone explain how i can use the username to query a DB table (tblUsrs) so as to make this happen


Regards

Paul
 
something like...
Code:
set rs=server.createobject("adodb.recordset")
set conn=server.createobject("adodb.connection")
conn.open "your connection string to the db"

sql= Select userID FROM UsersTable WHERE myUsername='"&request("hidName")&"'

Set rs=conn.execute(sql)

if rs.EOF AND rs.BOF then
'user does not exist
'show table 1
else
'user exists
'show table 2
end if

'close all your objects here

-DNG
 
an amendment to DNG's code:
Code:
[s][red]set rs=server.createobject("adodb.recordset")[/red][/s]
Set conn = server.createobject("adodb.connection")
conn.open "your connection string to the db"

sql = [red]"[/red]SELECT userID FROM UsersTable WHERE myUsername='" & Request[red].Form[/red]("hidName") & "'[red]"[/red]

Set rs=conn.execute(sql)

if rs.EOF AND rs.BOF then
'user does not exist
'show table 1
else
'user exists
'show table 2
end if

[red]
Set rs = Nothing
conn.close
Set conn = Nothing
[/red]

Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
Thanks for corrections Tony. i think Paul might have already got the idea...

-DNG
 
Guys, I have tried the code withour success however it is my fault and not yours as you might expect. Let me set the scene

All of these pages are on our Company Intranet, when the user opens the browser they go to an initial 3 frame frameset containing the following pages

default.htm
TopFrame.asp
MainFrame.asp

in TopFrame .asp
there are a number of links to other 3 frame framesets for various departments i.e

Sales,Production,Accounts etc.

I used the ValImage code to populate the hidUser field thinking that when i clicked on a link lets say for ProductionHome.htm that the value in hidUser would be available to use against a recordset in ProductionTopMenu.asp,(First Mistake).

Frameset for Production has the following pages

ProductionHome.htm
ProductionTopMenu.asp
ProductionMainPage.asp

Then I tried to use a session variable based on the value of ValImage but because the links goes to the Frameset page i.e. mydomain/Production.htm then the top menu page Production/topmenu.asp does not appear to be able to retrieve the session variable i have created.(Second Mistake).

I have checked this because if i set the link from the default TopFrame.asp page to go straight to Production/ProductionTopMenu.asp instead of Production/ProductionHome.htm, I can get the variable to use against my recordset.

Is there any way that I can store the username when the user opens the browser so that I can use it in any of my subsequent pages. Or am I trying to be too clever, any guidance you can give me on this would be much appreciated.




Regards

Paul
 
ok lets try this piece of sample code and try to adapt it to your needs:

Code:
<html>
<head>
<title>Passing Via a Frameset</title>
<frameset cols="*"> 
	<noframes>Your browser cannot 'do' frames</noframes>
	<frame src="passframe1.html"> 

</frameset>
</head>
</html>

Code:
<html>
<head><title> Page 1 </title></head>
<body>
<script type="text/javascript">
//<![CDATA[
if (typeof(parent.yourvariable)!="undefined"){
//keep this on one line
 document.write("In page 1 - I've got: " + 
 parent.yourvariable + "<BR /><BR />")
}
else
 document.write("In page 1 - There is no variable passed yet<BR /><BR />");
//]]>
</script>
<a href="#" 
   onclick="parent.yourvariable='hello';location.href='passframe2.html';return false;">
 Pass "hello"
</a>
</body></html>


hope you get the idea of how to get hold of the variables

-DNG
 
DNG,
thanks for the info however, becuase of my lack of knowledge concerning javascript i was struggling to create code to do the job so this is how i have overcome my problem.

1 On the home page i have set a textfield with the value of
Code:
<%=ValImage%>
and in my link i have placed the following

Code:
<a href="Somewhere/session.asp?UN=<%=ValImage%>"

so when the button is clicked the user is sent to an asp page called session.asp, i can now set up my session variable, then i do a
Code:
<%response.Redirect("Somewhere.htm")%>
to the pages where i want to use the variable. From here i can now use the code you supplied in an earlier post
Code:
if rs.EOF AND rs.BOF then
'user does not exist
'show table 1
else
'user exists
'show table 2
end if
to give me what i need. I am trying to learn javascript at the moment I may then try out the other suggestion you gave me.

Anyway thanks for your help

[2thumbsup]



Regards

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top