This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Dreamweaver > October 2005 > Session variable





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Session variable
VegaLA

2005-08-18, 7:43 pm

Hi all,
i'm still working on my 'search' page but have made some progress !
What i need to do now is pass a session variable to the next page. I have a
text box on a form and a session variable called ptype. i have bind the session
to the empty text box for the user to type in. The form has a submit button and
the code to open the enxt page is as follows...

srchresults.asp?ID=<%= Session("ptype") %>

The next page should list the results filtered from the session variable but
when the results page opens the URL at the top of the page looks like this...

http://localhost/mysite/Intranet/srchresults.asp?ID=

The text the user input in the textfield is not there.
when i open the recordset property for the results page and test it by
manually typing in text it pulls up results !!
Can anyone advise me on where I am going wrong please ?

Mitch........

PaulSelden

2005-08-18, 7:43 pm

I'm not completely sure I understand what you are trying to do, so I'll explain
two methods.

1:
Session variables are inherently stored until the user ends the session
(usually by closing the browser), so there is no need to pass them through a
querystring in the URL. Simply using <% Session("ptype") =
Request("<textname>") %> will store the value that was entered in <textname> in
the session variable "ptype". You can then use it on another page by calling
Session("ptype") any time you want to use that variable. (You won't be able to
set the session variable to the value of the text box until after the form is
submitted, so if the "action=" sends it to another page, the session variable
will be an empty string ( "" )) If you wanted to store the session variable
and then send it to the results page, you'd have to set
action="<thesamepage>.asp" and then put the code that I mentioned up top at the
top of the page, then use <%Response.Redirect "srchresults.asp?ID=" &
Session("ptype") %> to redirect to the results page.

2. It sounds like you don't even need to use a session variable to do what
you want to accomplish. Name the text box something like "ptype", set the form
action="srchresults.asp", and on srchresults.asp you can get the value that was
in the text box by using Request("ptype").

Hope this helps.

VegaLA

2005-08-18, 7:43 pm

Thanks Paul,
I have decided to give your second suggestion a try
but i'm not sure how to use the 'request(ptype)' code you mentioned. Is this
done setting the filter in the recordset for the results page ?

Mitch....

PaulSelden

2005-08-18, 7:43 pm

Oh I'm sorry. I thought you were manually editing the code for this.

Yes, you would set the Filter to whatever column you want it to filter by,
then select either URL Parameter or Form from the dropdown below that one (URL
Parameter if your form has GET as the method, and Form if your form has POST as
the method). Then in the last filter field put the name of the text box that
you had on your form. To use multiple filters you'll have to click on Advanced
and copy the syntax there.

As an aside, in case you wondering, the URL Parameter option will insert code
that looks something like <% Request.Querystring("fieldname") %> and the Form
option will insert code like <% Request.Form("fieldname") %>. .Querystring
will grab the value that is appended to the URL (you saw the ?ID= added on
there) and then grab the value on the new page from there. .Form will collect
the data that was "secretly" passed by the from through the POST method. The
code I mentioned <% Request("fieldname") %> will grab the data from either of
these. Since users can manually append ?ID=etc... to the end of the URL, if
you don't want users looking at certain records, you'll want to use POST and
Request.Form(). Also if you are having the user enter a large amount of text
you'll want to use POST as well, since the maximum size of a URL is somewhere
around 2024 characters.

Any questions - ask!

VegaLA

2005-08-18, 7:43 pm

I hope some day soon i'm competent enough to edit the code manually but not
just yet :)

Anyway, your advice has saved the day, it worked perfectly !! This task has
been bothering me for a few days now so its nice to get the functionality
working, I just have to tidy up the design now.

Thanks again for your solution, you've saved my neck !!

Mitch...

bregent

2005-10-25, 6:29 pm

In article <1130205871.363293.172550@g43g2000cwa.googlegroups.com>,
masta_d_funk@hotmail.com says...
>
>Hey
>
>I have a problem using dreamweaver. The problem is im creaing a login
>page that accepts the username and password. When the user logins i
>only want their information displayed. My columns for the username
>consists of UserID, Username and Password. And my other table is called
>Data consisting of UserID, Email, Address, etc.. When the user logins i
>want it to check in the Data table for the UserID so that it displays
>his/her information only. i know i can do it if i had a Username column
>in the Data table, but i do not want that..
>
>im currently using dreamweavers login authentication wizard..which
>takes in 2 values..the username and password..i need help on creating a
>recordset that will user the users UserID and will link it to the Data
>UserID column..


There are a couple of ways to handle this. First of all, are you sure you can't
combine those fields in a single table? I don't know your schema or data, but
those fields are related to users and might belong together.

If the columns do belong in 2 tables, then you need to write SQL to join the
tables together on the common UserID field. You need to go to the Advanced tab
on the RecordSet dialog and enter your SQL.

Another option is to create a view in your DBMS (in Access you could use a
query) that joins the tables, and then select the view from the Recordset
dialog. But for a simple query like yours, this is overkill.

masta_d_funk@hotmail.com

2005-10-31, 6:29 pm

ok thx...ive tried creating the advanced SQL statement..my SQL
statement is like this:
SELECT tblCustomer.sUsername, tblIssue.sIssueNumber,
tblIssue.iIssueDate, tblIssue.sZIP, tblIssue.sEXE, tblIssue.sPDF
FROM tblCustomer INNER JOIN tblIssue ON
tblCustomer.iUserID=tblIssue.iUserID;
WHERE tblIssue.iUserID = tblCustomer.iUserID

But when i want to use the iUserID as a session variable it displays an
error message. My session variable is Session("MM_Username) where the
MM_Username is the sUsername is my table...

Im creating a website that has 2 tables, when the user accesses the
website..he/she can only download the updates that are currently issued
to them..So that is why ive created 2 tables..one of the user details
and the other is the table where it looks up for the iUserID...

Can you please help me?

masta_d_funk@hotmail.com

2005-10-31, 10:20 pm

ok thx...ive tried creating the advanced SQL statement..my SQL
statement is like this:
SELECT tblCustomer.sUsername, tblIssue.sIssueNumber,
tblIssue.iIssueDate, tblIssue.sZIP, tblIssue.sEXE, tblIssue.sPDF
FROM tblCustomer INNER JOIN tblIssue ON
tblCustomer.iUserID=tblIssue.iUserID;
WHERE tblIssue.iUserID = tblCustomer.iUserID

But when i want to use the iUserID as a session variable it displays an
error message. My session variable is Session("MM_Username) where the
MM_Username is the sUsername is my table...

Im creating a website that has 2 tables, when the user accesses the
website..he/she can only download the updates that are currently issued
to them..So that is why ive created 2 tables..one of the user details
and the other is the table where it looks up for the iUserID...

Can you please help me?

bregent

2005-10-31, 10:23 pm

In article <1130801635.319726.306990@g14g2000cwa.googlegroups.com>,
masta_d_funk@hotmail.com says...
>
>ok thx...ive tried creating the advanced SQL statement..my SQL
>statement is like this:
>SELECT tblCustomer.sUsername, tblIssue.sIssueNumber,
>tblIssue.iIssueDate, tblIssue.sZIP, tblIssue.sEXE, tblIssue.sPDF
>FROM tblCustomer INNER JOIN tblIssue ON
>tblCustomer.iUserID=tblIssue.iUserID;
>WHERE tblIssue.iUserID = tblCustomer.iUserID
>
>But when i want to use the iUserID as a session variable it displays an
>error message. My session variable is Session("MM_Username) where the
>MM_Username is the sUsername is my table...
>
>Im creating a website that has 2 tables, when the user accesses the
>website..he/she can only download the updates that are currently issued
>to them..So that is why ive created 2 tables..one of the user details
>and the other is the table where it looks up for the iUserID...


OK, first of all, I'm not that familiar with mysql join syntax as I don't use
that DBMS. But it seems to me that you have a redundant join in the where
clause. In other DBMS's, you can either use the join keyword, or put the join in
the where clause - but not use both.

What you don't have in the where clause is the UserID that the user logged in
with. So you are probably getting multiple rows returned. You need to restrict
the result set to the user that has logged in by including the session variable
in the where clause. Or is that where you are having the problem?

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews