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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lost session variable?

Status
Not open for further replies.

longmatch

Programmer
Nov 1, 2001
406
Dear ALL:
I used following code to collect user information and set a session variable for residentName.
<SELECT size=1 id=select1 name=ResidentName VALUE=&quot;<%=session(&quot;ResidentName&quot;)%>&quot;>
<% do until rsResidentName.EOF%>
<option Value= <%=rsResidentName(&quot;BaylorID&quot;)%>><%=rsResidentName(&quot;Lastname&quot;)%>, <%=rsResidentName(&quot;Firstname&quot;)%></option>
<% rsResidentName.MoveNext
loop
</SELECT> <br><br>

But I can not refer this session variable when I write a query as follow.
strQuery = &quot;SELECT DISTINCT prococedure, count(prococedure) as Procedurecount FROM FORM_ID_198163500 &quot;
strQuery = strQuery & &quot;WHERE Category = '&quot; & Details & &quot;'&quot;
strQuery = strQuery & &quot; AND baylorID = '&quot; & session(&quot;residentName&quot;) & &quot;'&quot;
strQuery = strQuery & &quot; GROUP BY Prococedure;&quot;
%>

How can I set a session variable and how to refer a session variable in a query?

Thanks

Haijun

 
hey u r using sesion variable perfectly but it must reinitialize again some where
plz post your entire code for better help

prasad

sawantprasad2001@yahoo.com

 
Dear Prasad:
In my first page, user can select a username to get their procedure record by different categories. After their selection, and click &quot;submit&quot; button, second page appears with the query result. When user click the category link, another query page will show up, with detailed procedure in that category. In addition to the category, I need to write a query using username, which in on the first page. I used a session variable, but it did not work on the third page.

Could you tell me why my code does not work.

Thanks

Haijun

My first page
<!--#include file=&quot;ClssfdPage.asp&quot;-->


<BASEFONT FACE=&quot;serif&quot; COLOR=&quot;black&quot;>
<HTML>
<HEAD>
<TITLE>Procedure Summary by Resident</TITLE>
</HEAD>

<BODY BGCOLOR=&quot;#FFFF80&quot; text=blue>


<%
dim rsResidentName
dim rsCategory

dim strResidentName
dim strCategory

set rsResidentName = Server.CreateObject(&quot;ADODB.Recordset&quot;)
set rsCategory = Server.CreateObject(&quot;ADODB.Recordset&quot;)

strResidentName = &quot;SELECT Firstname, lastName, BaylorID FROM person order by lastname, firstname&quot;
strCategory = &quot;SELECT * FROM category&quot;

rsResidentName.Open strResidentName, objConn,adOpenKeyset,adLockOptimistic
rsCategory.Open strCategory, objConn,adOpenKeyset,adLockOptimistic

%>
<H2 align=center>Procedure Summary by Residents </h2>
<form name=summaryByResident Action=summaryByresident1.asp method = post>
<center>
Resident Name
<SELECT size=1 id=select1 name=ResidentName VALUE=&quot;<%=session(&quot;ResidentName&quot;)%>&quot;>
<% do until rsResidentName.EOF%>
<option Value= <%=rsResidentName(&quot;BaylorID&quot;)%>><%=rsResidentName(&quot;Lastname&quot;)%>, <%=rsResidentName(&quot;Firstname&quot;)%></option>
<% rsResidentName.MoveNext
loop
%>

</SELECT> <br><br>
Procedure Category
<SELECT size=1 id=select2 name=Category2 VALUE=&quot;<%= session(&quot;category&quot;)%>&quot;>
<% do until rsCategory.EOF%>
<option value =<%=rsCategory(&quot;categoryAbbrev&quot;)%> ><%=rsCategory(&quot;category&quot;)%></option>
<% rsCategory.MoveNext
loop
%>

</SELECT> <br>

<b>Start Date (mm/dd/yy) <INPUT type=&quot;text&quot; name=StartDate size = 10> <br></B>
<b>End Date (mm/dd/yy)&nbsp <INPUT type=&quot;text&quot; name=EndDate size = 10></b>
<br><br><br>

<INPUT type=&quot;submit&quot; value=&quot;Summary by Residents&quot; id=submit1 name=submit1>
</center>
</form>
<HR>
<TABLE BORDER=0 WIDTH=100%>
<TR ALIGN=CENTER>
<TD WIDTH=33%><A HREF=&quot;SummaryByResident.asp&quot;>Summary By Resident</A></TD>
</TR>
<TR ALIGN=CENTER>
<TD WIDTH=33%><A HREF=&quot;datainput1.asp&quot;>Add new procedure</A></TD>
</TR>
<TR align = center>
<TD><A HREF=&quot;newpassword.asp&quot;>Change your Password<a></TD>
</TR>
</TABLE>

</BODY>
</HTML>
My second page
<!--#include file=&quot;ClssfdPage.asp&quot;-->


<BASEFONT FACE=&quot;serif&quot; COLOR=&quot;black&quot;>
<HTML>
<HEAD>
<TITLE>Procedure Summary by Resident</TITLE>
</HEAD>

<BODY BGCOLOR=&quot;#FFFF80&quot; text=blue>
<H2 Align=center> Procedure Summary by Residents </h2>

<%
Dim rsSummary

dim strSQLSummary

dim strSelectedName
dim strSelectedCategory

Set rsSummary = Server.CreateObject(&quot;ADODB.Recordset&quot;)

strSelectedName = Request.Form(&quot;ResidentName&quot;)
strSelectedCategory = Request.Form (&quot;Category2&quot;)

strSQLSummary = &quot;SELECT Count(Prococedure) AS NOProcedure, category FROM FORM_ID_198163500 &quot;
strSQLSummary = strSQLSummary & &quot;WHERE BaylorID= &quot;&quot;&quot; & strSelectedName & &quot;&quot;&quot;&quot; & &quot; GROUP BY category;&quot;

rsSummary.Open strSQLSummary, objConn,adOpenKeyset,adLockOptimistic

If Not rsSummary.EOF Then ' current user has Procedures
Response.Write _
&quot;<TABLE align = &quot;&quot;center&quot;&quot; BORDER=&quot;&quot;1&quot;&quot; CELLSPACING=&quot;&quot;3&quot;&quot; CELLPADDING=&quot;&quot;3&quot;&quot;>&quot; & _
&quot;<TR>&quot; & _
&quot; <TH>Category<BR>&quot; & _
&quot; <TH>No. of Procedure<BR>&quot; & _
&quot;</TR>&quot;
Do While Not rsSummary.EOF
Response.Write _
&quot;<TR ALIGN=CENTER>&quot; & _
&quot; <TD>&quot; & &quot;<a href='ProcedureDetails.asp?Details=&quot; & rsSummary(&quot;category&quot;) & &quot;'>&quot; & rsSummary(&quot;category&quot;) & &quot;</a>&quot; & &quot;</TD>&quot; & _
&quot; <TD>&quot; & rsSummary(&quot;NoProcedure&quot;) & &quot;</TD>&quot; & _
&quot;</TR>&quot;
rsSummary.MoveNext
Loop
Response.Write &quot;</TABLE>&quot;
Else ' current user has no Procedures
Response.Write &quot;<CENTER><H2>No Procedures found</H2></CENTER>&quot;
End If
rsSummary.close
%>


<HR>
<TABLE BORDER=0 WIDTH=100%>
<TR ALIGN=CENTER>
<TD WIDTH=33%><A HREF=&quot;SummaryByResident.asp&quot;>Summary By Resident</A></TD>
</TR>
<TR ALIGN=CENTER>
<TD WIDTH=33%><A HREF=&quot;datainput1.asp&quot;>Add new procedure</A></TD>
</TR>
<TR align = center>
<TD><A HREF=&quot;newpassword.asp&quot;>Change your Password<a></TD>
</TR>
</TABLE>

</BODY>
</HTML>


My third ASP page
<!--#include file=&quot;ClssfdPage.asp&quot;-->
<%
dim rsProcedures, strQuery, details, residentName
residentname = session(&quot;ResidentName&quot;)

Details = trim(request(&quot;Details&quot;))

set rsProcedures =server.CreateObject(&quot;adodb.recordset&quot;)
Response.Write (session(&quot;residentName&quot;))
strQuery = &quot;SELECT DISTINCT prococedure, count(prococedure) as Procedurecount FROM FORM_ID_198163500 &quot;
strQuery = strQuery & &quot;WHERE Category = '&quot; & Details & &quot;'&quot;
strQuery = strQuery & &quot; AND baylorID = '&quot; & session(&quot;residentName&quot;) & &quot;'&quot;
strQuery = strQuery & &quot; GROUP BY Prococedure;&quot;

rsProcedures.Open strQuery, objConn,adOpenKeyset,adLockOptimistic

if rsProcedures.EOF then
Response.Write &quot;There are no details available for &quot; & request(&quot;Details&quot;)
end if

If Not rsProcedures.EOF Then ' current user has Procedures
Response.Write _
&quot;<TABLE align = &quot;&quot;center&quot;&quot; BORDER=&quot;&quot;1&quot;&quot; CELLSPACING=&quot;&quot;3&quot;&quot; CELLPADDING=&quot;&quot;3&quot;&quot;>&quot; & _
&quot;<TR>&quot; & _
&quot; <TH>Procedure<BR>&quot; & _
&quot; <TH>Count<BR>&quot; & _
&quot;</TR>&quot;
Do While Not rsProcedures.EOF
Response.Write _
&quot;<TR ALIGN=CENTER>&quot; & _
&quot; <TD>&quot; & rsProcedures(&quot;Prococedure&quot;) & &quot;</TD>&quot; & _
&quot; <TD>&quot; & rsProcedures(&quot;Procedurecount&quot;) & &quot;</TD>&quot; & _
&quot;</TR>&quot;
rsProcedures.MoveNext
Loop
Response.Write &quot;</TABLE>&quot;
Else ' current user has no Procedures
Response.Write &quot;<CENTER><H2>No Procedures found</H2></CENTER>&quot;
End If

%>

<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>
 
I don't see where you're setting a session variable at all. You'd have to set your session like so:

session(&quot;ResidentName&quot;) = &quot;something&quot;

Hope this helps.

Choo Khor
choo.khor@intelebill.com
 
Dear Khorjak:

I know how to use session variable right now. I have another question about my code (see below):

<SELECT size=1 id=select1 name=ResidentName VALUE=&quot;<%=session(&quot;ResidentName&quot;)%>&quot;>
<% do until rsResidentName.EOF%>
<option Value= <%=rsResidentName(&quot;BaylorID&quot;)%>><%=rsResidentName(&quot;Lastname&quot;)%>, <%=rsResidentName(&quot;Firstname&quot;)%></option>
<% rsResidentName.MoveNext
loop
</SELECT> <br><br>

I know how to set session variable for baylorID using:
session(&quot;baylorID&quot;) = request(&quot;residentname&quot;)
How can I pass resident first name and last name to next page?

Haijun
 
you can put the value into a hidden form field and then use a querystring to obtain it in the next page
<input type=hidden name=var1 value=&quot;<% something%>&quot;>

call it
request.querystring(&quot;var1&quot;) You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
Dear onput:
It is a good idea to use hidden field to carry the values over. Obviously the value of hidden field is based upon user's selection. Where do I need to put the hidden field? How to set up the value? You know the value for my combo box is different from the value in the box. The selection is name, the value for the selection is baylorID.


Thanks

Haijun
 
I think this is what you're looking for:

<html>
<head>
<script language=JavaScript>
function setVal(x){
document.frmTest.sName.value=x;
}
</script>
</head>

<body>
<form name=frmTest>
<input type=hidden name=sName value=&quot;&quot;>
<select name=nID onchange=&quot;setVal(this.options[this.selectedIndex].text)&quot;>
<option value=1028>Doe, John</option>
<option value=2028>Doe, Jane</option>
<option value=3028>Smith, Bob</option>
</select>
</form>
</body>
</html>

To retrieve the name on the next page:
strName = Request.Form(&quot;sName&quot;)


Choo Khor
choo.khor@intelebill.com
 
One addition, if you are going to pick this up as the querystring on the next page then you will need to mark this form as GET:
Code:
<form name=frmTest action=GET>
-Tarwn ------------ My Little Dictionary ---------
Reverse Engineering - The expensive solution to not paying for proper documentation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top