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

How to create a "Session ID" from a newly inserted record...

DreamWeaver 101

How to create a "Session ID" from a newly inserted record...

by  TonyU  Posted    (Edited  )
[tt][color navy]

Here's a way to create a Session ID from a newly inserted record from a database.

**********************************************
[color green]'Immediatelly after your insert statement be sure to comment out the following statements:
[ul][li][color green]' MM_editCmd.ActiveConnection.Close[/color]
[/li] [li][color green]'Response.Redirect(MM_editRedirectUrl)[/color]
[/li][/ul]
as shown below and adding [color blue]the script in blue[/color]
[/color]

MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
[color green]' execute the insert[/color]
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
[color green]' MM_editCmd.ActiveConnection.Close[/color]

If (MM_editRedirectUrl <> "") Then
[color green]'Response.Redirect(MM_editRedirectUrl)[/color]
End If
End If

End If
%>
[color blue]<%
If (CStr(Request("MM_insert")) <> "") Then
set TonyRS = Server.CreateObject("ADODB.Recordset")
TonyRS.ActiveConnection = MM_editCmd.ActiveConnection
TonyRS.Source = "SELECT max(id) as MaxID FROM YOUR_TABLE"
TonyRS.CursorType = 0
TonyRS.CursorLocation = 2
TonyRS.LockType = 3
TonyRS.Open()
Session("NewID")=TonyRS("MaxID")
Response.Redirect(MM_editRedirectUrl)
end if
%>
[/color]
**********************************************

As you can see, I'm selecting the MAX (id) from the database and creating a session("NewID") that you can call from anywhere you need to.

I hope this faq helps you.

Thanks
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top