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

Session variable question

Status
Not open for further replies.

mtarby

Programmer
Feb 19, 2003
89
US
In my on again, off again attempt to get a problem with a series of web forms straightened out, I came up with a new question about session variables.

I've got a two part application form. Once the user completes part 1, it inserts into a database table where I've got an auto-number applicant_id field.

My question - I want the applicant_id to carry over to the next page and insert into the next database table.

Since its an auto number field, can I use this as session variable, or does the session variable need to be a field from the form where the applicant enters data?

Thanks in advance.
 
you can put just about anything you want in a session variable, within obvious and sensible limitations

Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
You just have to watch our how many sessions you have running, and how much traffic you have. Each session takes a bit of server memory for a little while before being released. Don't want to watch a slow server fall to it's knees... or then again....

Just my two cents
 
it's better to use the client unique id that you reference in the DB, that way it's just a simple number that will relate the client in anyway to your database, versus some arbitrary identifyer that you would then need to derive the proper associations. so in response to your question, yes you can do that and it's recommended

[thumbsup2]DreX
aKa - Robert
 
So then I'm guessing I'm doing something wrong when I try to set the session variable. Following my form that inserts the preliminary info into the first database table, here's the code I use to set it:

Code:
<%
dim applicant_id
set applicant_id = Server.CreateObject("ADODB.Recordset")
applicant_id.ActiveConnection = MM_[URL unfurl="true"]www_STRING[/URL]
applicant_id.Source = "SELECT applicant_id  FROM dbo.hr_applicant_info"

applicant_id = Request("applicant_id")
Session("applicant_id")=applicant_id
%>

Does anyone have any suggestions?
 
>>got an auto-number

i dont think u can get the auto-number value after u insert it into the database, what database are u using???

Known is handfull, Unknown is worldfull
 
That's what I was wondering. I'm using an SQL database
 
u cannot do it in SQL Server, its better that u generate the id urself and then add the id to a session...

Known is handfull, Unknown is worldfull
 
Thanks - that's what I needed - I'll try something else!
 
vbkris said:
i dont think u can get the auto-number value after u insert it into the database

If you using sprocs instead of inline sql you can return the auto_id pk uing either the @@identity keyword or the Scope_Identity function.

something like:

Code:
Create Procedure dbo.insertTest(

	@val1 as varchar(50),
	@val2 as varchar(50)
)

AS

Insert INTO [Customers](column1, column2) VALUES (@val1, @val2)

IF @@ERROR = 0 
	BEGIN
		SELECT SCOPE_IDENTITY --Returns AutoID
	END
ELSE
	SELECT -1
 
What I did was just set up a randomly generated number as a hidden form variable and used that as my session variable. Now its working great.

Thanks everyone for the advice and explanation
 
you can also use the GUID as a random-ish variable to track a client, and post it to the DB, then use this to retrieve the uni-ID after the fact.

[thumbsup2]DreX
aKa - Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top