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!

I'm comfused with creating Session("Variables") - please help 2

Status
Not open for further replies.

TonyU

Technical User
Feb 14, 2001
1,317
US
[tt]
Ok guys here's the deal, I've created a form in dreamweaver that inserts into an access database (no problem there)

Here's the problem
I need to create variables of all the fiels in order to request the data just entered on my results page.


Here's my code
Note: I checked the database and the inserting works fine.

<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<!--#include file=&quot;Connections/delivery.asp&quot; -->
<%
' *** Edit Operations: declare variables

MM_editAction = CStr(Request(&quot;URL&quot;))
If (Request.QueryString <> &quot;&quot;) Then
MM_editAction = MM_editAction & &quot;?&quot; & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = &quot;&quot;
%>
<%
' *** Insert Record: set variables

If (CStr(Request(&quot;MM_insert&quot;)) <> &quot;&quot;) Then

MM_editConnection = MM_delivery_STRING
MM_editTable = &quot;delivery&quot;
MM_editRedirectUrl = &quot;results.asp&quot;
MM_fieldsStr = &quot;Requested_Date|value|Pickup_Delivery_Date|value|Task|value|AR|value|JobNumber|value|Client|value|Project|value|Address|value|City|value|State|value|Zip|value|Contact|value|Items|value|Driver|value|Courier|value|Status|value|Payment|value|Charges|value|Comments|value&quot;
MM_columnsStr = &quot;requested_date|#,none,NULL|pickup_delivery_date|#,none,NULL|task|',none,''|ar|',none,''|jobnumber|',none,''|client|',none,''|project|',none,''|address|',none,''|city|',none,''|state|',none,''|zip|',none,''|contact|',none,''|items|',none,''|driver|',none,''|courier|',none,''|status|',none,''|payment|',none,''|charges|',none,''|comments|',none,''&quot;

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, &quot;|&quot;)
MM_columns = Split(MM_columnsStr, &quot;|&quot;)

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(Request.Form(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> &quot;&quot; And Request.QueryString <> &quot;&quot;) Then
If (InStr(1, MM_editRedirectUrl, &quot;?&quot;, vbTextCompare) = 0 And Request.QueryString <> &quot;&quot;) Then
MM_editRedirectUrl = MM_editRedirectUrl & &quot;?&quot; & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & &quot;&&quot; & Request.QueryString
End If
End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

If (CStr(Request(&quot;MM_insert&quot;)) <> &quot;&quot;) Then

' create the sql insert statement
MM_tableValues = &quot;&quot;
MM_dbValues = &quot;&quot;
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),&quot;,&quot;)
Delim = MM_typeArray(0)
If (Delim = &quot;none&quot;) Then Delim = &quot;&quot;
AltVal = MM_typeArray(1)
If (AltVal = &quot;none&quot;) Then AltVal = &quot;&quot;
EmptyVal = MM_typeArray(2)
If (EmptyVal = &quot;none&quot;) Then EmptyVal = &quot;&quot;
If (FormVal = &quot;&quot;) Then
FormVal = EmptyVal
Else
If (AltVal <> &quot;&quot;) Then
FormVal = AltVal
ElseIf (Delim = &quot;'&quot;) Then ' escape quotes
FormVal = &quot;'&quot; & Replace(FormVal,&quot;'&quot;,&quot;''&quot;) & &quot;'&quot;
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & &quot;,&quot;
MM_dbValues = MM_dbValues & &quot;,&quot;
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = &quot;insert into &quot; & MM_editTable & &quot; (&quot; & MM_tableValues & &quot;) values (&quot; & MM_dbValues & &quot;)&quot;
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject(&quot;ADODB.Command&quot;)
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
'I'm sure I'm setting my sessions wrong

'Session(&quot;form&quot;) = Request.Form(&quot;requested_date&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;pickup_delivery_date&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;task&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;ar&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;jobnumber&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;client&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;project&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;address&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;city&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;state&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;zip&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;contact&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;items&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;driver&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;courier&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;status&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;payment&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;charges&quot;)
'Session(&quot;form&quot;) = Request.Form(&quot;comments&quot;)

If (MM_editRedirectUrl <> &quot;&quot;) Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>


Thanks in advance guys.
[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 

you can't name all the session var's the same
session(&quot;form&quot;)
session(&quot;form2&quot;)
etc
[bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
[tt]
so, I should name them like:

'Session(&quot;requested_date&quot;) = Request.Form(&quot;requested_date&quot;)
'Session(&quot;pickup_delivery_date&quot;) = Request.Form(&quot;pickup_delivery_date&quot;)
'Session(&quot;task&quot;) = Request.Form(&quot;task&quot;)
etc
etc

Then on my results page when I request the session I should only request one session?? or should I request all of them if I'm clear
[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
yes name them like that

and when you request them you call them one at a time
so if
insert page
session(&quot;text1&quot;) = Request.Form(&quot;text1&quot;)

view page
<td><%
Response.Write session(&quot;text1&quot;)
%></td> [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
[tt]Working on it now. I'll let you know. Thanks
[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
[tt]I tested it no values came across. am I assigning the session(s) on the wrong spot on my page? I thought I woudl set them before the re-direct...
[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
It looks like you have a GET mehtod in your form tag sense I see some Request.QueryString's up there.
in that case
Session(&quot;text1&quot;) = Request.QueryString(&quot;text1&quot;)

Also I would do this in the beginning of the page

If you save all of your form values like this then you can change the remaining code around to use the var's and that would take care of the chance you are trying to change or give values to the save instance more then once.


Session(&quot;text1&quot;) = Request.QueryString(&quot;text1&quot;)
dim field1
field1 = Session(&quot;text1&quot;)

this is a way to clean your code up that I like to use.
Not sure about the whole MM_ situation though.
(dreamweaver)

maybe there is someone out there that knows more about dreamweaver, I do everything in interdev and notepad so I'm at a loss there.
hope that helps [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Hey onpnt what about using array in the session?

Session(&quot;FormItem(0)&quot;) = Request.QueryString(&quot;text1&quot;)

Just a thought..
Not sure if that works or not.
 
I thought of that also and it's a awesome way of passing form values [hence the star] but I wanted to try and make this as straight forward as possible if it being the first use of session var etc..

also don't know how it will go with the MM issue and after the week I have been having on trying to help out I didn't wnat another strike against me[lol] [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Well its only right you get a star too!

Oh, and how can you get a strike against you?

Thanks for the star!
 
strike out on helping someone

if I give bad info I take that as a strike against myself. just a personal thing. hate to steer people the wrong way. besides they're here for help not have things made worse [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
[tt]Ok I'm back, I changed all my sessions as you suggested but I'm stil not getting anything to display when on my results page I use the session

can you guys verify that my sessions are being declared in the right spot in my code??

[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
Trying to place a declare session or many similiar type of items is difficult with Dreamweaver. I often find the need to go &quot;out of the box&quot; with Dreamweaver - it's typically faster, easier (both to write and to see) an insert code and your session variables by hand.

&quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Unless I severely messed up this should work.

Take your first page with the form - remove the MM insert record behavior - change the form's tag to:

<form name=&quot;form1&quot; Method=&quot;post&quot; action=&quot;adddelivery.asp&quot;>

Now, create a new blank page - highlight whatever code MM puts in (you need to be on the code page for this)

and replace it with this. - and please don't just cut and paste, cut, paste and look at it - see why it's doing what. It's not terribly difficult and will help you in the future.


<%@LANGUAGE=&quot;VBSCRIPT&quot;%>

<!--#include file=&quot;Connections/delivery.asp&quot; -->
<% 'Declaring Sessions
Session(&quot;svRequestDate&quot;) = Request.Form(&quot;requested_date&quot;)
Session(&quot;svPickupDate&quot;) = Request.Form(&quot;pickup_delivery_date&quot;)
Session(&quot;svTask&quot;) = Request.Form(&quot;task&quot;)
Session(&quot;svAR&quot;) = Request.Form(&quot;ar&quot;)
Session(&quot;svJobNumber&quot;) = Request.Form(&quot;jobnumber&quot;)
Session(&quot;svClient&quot;) = Request.Form(&quot;client&quot;)
Session(&quot;svProject&quot;) = Request.Form(&quot;project&quot;)
Session(&quot;svAddress&quot;) = Request.Form(&quot;address&quot;)
Session(&quot;svCity&quot;) = Request.Form(&quot;city&quot;)
Session(&quot;svState&quot;) = Request.Form(&quot;state&quot;)
Session(&quot;svZip&quot;) = Request.Form(&quot;zip&quot;)
Session(&quot;svContact&quot;) = Request.Form(&quot;contact&quot;)
Session(&quot;svItems&quot;) = Request.Form(&quot;items&quot;)
Session(&quot;svDriver&quot;) = Request.Form(&quot;driver&quot;)
Session(&quot;svCourier&quot;) = Request.Form(&quot;courier&quot;)
Session(&quot;svStatus&quot;) = Request.Form(&quot;status&quot;)
Session(&quot;svPayment&quot;) = Request.Form(&quot;payment&quot;)
Session(&quot;svCharges&quot;) = Request.Form(&quot;charges&quot;)
Session(&quot;svComments&quot;) = Request.Form(&quot;comments&quot;)
%>
<%
Dim RS
set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.ActiveConnection = MM_Delivery_STRING
rs.Source = &quot;SELECT Top 1 * FROM Delivery&quot;
rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 3
rs.Open()
%>
<%
rs.addnew
rs(&quot;Requested_Date&quot;)= Session(&quot;svRequestDate&quot;)
rs(&quot;Pickup_Delivery_Date&quot;)= Session(&quot;svPickupDate&quot;)
rs(&quot;Task&quot;)= Session(&quot;svTask&quot;)
rs(&quot;AR&quot;)= Session(&quot;svAR&quot;)
rs(&quot;Client&quot;)= Session(&quot;svClient&quot;)
rs(&quot;Project&quot;)= Session(&quot;svProject&quot;)
rs(&quot;Address&quot;)= Session(&quot;svAddress&quot;)
rs(&quot;City&quot;)= Session(&quot;svCity&quot;)
rs(&quot;State&quot;)= Session(&quot;svState&quot;)
rs(&quot;Zip&quot;)= Session(&quot;svZip&quot;)
rs(&quot;Contact&quot;)= Session(&quot;svContact&quot;)
rs(&quot;Items&quot;)= Session(&quot;svItems&quot;)
rs(&quot;Driver&quot;)= Session(&quot;svDriver&quot;)
rs(&quot;Courier&quot;)= Session(&quot;svCourier&quot;)
rs(&quot;Status&quot;)= Session(&quot;svStatus&quot;)
rs(&quot;Payment&quot;)= Session(&quot;svPayment&quot;)
rs(&quot;Charges&quot;)= Session(&quot;svCharges&quot;)
rs(&quot;Comments&quot;)= Session(&quot;svComments&quot;)
rs.update
response.redirect &quot;results.asp&quot;
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
</body>
</html>
&quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
forgot - save the new page as adddelivery.asp &quot;Damn the torpedoes, full speed ahead!&quot;

-Adm. James Farragut

Stuart
 
Thank you very much schase, I will try it as soon as I get to work.
[tt]&quot;A Successful man is one who can build a firm foundation with the bricks that others throw at him&quot;[/tt]
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top