Generating ID or Session Problem? Options

This is a discussion on "Generating ID or Session Problem? Options" within the Classic ASP section. This forum, and the thread "Generating ID or Session Problem? Options are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Reply
 
LinkBack Thread Tools
  #1  
Old Jul 28th, 2006, 18:26
New Member
Join Date: Jul 2006
Location: Philippines
Age: 28
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Generating ID or Session Problem? Options

Hi everyone, i'm currently developing an online shopping cart, the order number is automatically generated.
Once i started to shop it's working fine. Then if i tried to shop using other pc, i encountered wierd thing,
wherein the order number is being started from 1 again.

e.g. orderNo: 60727001

then, once the transaction is done, it will be incremented by 1. But when i try to shop again using other computer, orderNo will be set to 60727001 again.

Below is my code in Generating OrderNo:

==============================

theYear = right(year(now()), 2)
theMonth = month(now())
theDay = day(now())

if theMonth < 10 then
theMonth = "0" & theMonth
end if

if theday < 10 then
theDay = "0" & theDay
end if

theDate = theYear & theMonth & theDay

Sub CreateNewOrder()
Application.lock

if Application("orderID") = "" then

sql = "SELECT MAX (orderID) AS theLast FROM orders WHERE Left(orderID, 6) = '" & theDate & "'"
set rs = Server.CreateObject("ADODB.RecordSet")
rs.Open sql, ConString , adLockReadonly

if NOT isNull(rs("theLast")) then
theLast = cInt(right(rs("theLast"), 3)) + 1
if theLast > 999 then
'ala lang
else
do while len(theLast) < 3
theLast = "0" & theLast
Loop
end if
else
theLast = "001"
end if

theLast = theDate & theLast

Application("orderID") = theLast
end if


intOrderID = Application("orderID")
Session("orderID") = intOrderID

strSQL = "SELECT * FROM orders WHERE NULL"

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQL, Conn, adOpenKeyset, adLockOptimistic, adCmdText

rs.AddNew
rs.Fields("status").Value = "OPEN"
rs.Fields("orderID") = intOrderID
rs.Update


Application("orderID") = Application("orderID") + 1

Application.Unlock

rs.Close
Set rs = Nothing

End Sub

Sub AddToOrder(nOrderID, nProductID, nQuant)

strSQL2 = "SELECT * FROM itemsOrdered"

Set rs2 = Server.CreateObject("ADODB.Recordset")
rs2.Open strSQL2, Conn, adOpenKeyset, adLockOptimistic, adCmdText

rs2.AddNew

rs2.Fields("orderID").Value = nOrderID
rs2.Fields("productID").Value = nProductID
rs2.Fields("quantity").Value = nQuant
rs2.Update

rs2.Close
Set rs2 = Nothing
End Sub


'Main program
intProdID = Request.form("intProdID")
intQuant = Request.form("intQuant")


intOrderID = CStr(Session("orderID"))

if intOrderID = "" then
CreateNewOrder
end if

sqlText = "SELECT * FROM itemsOrdered WHERE orderID =" & intOrderID & "AND productID =" & intProdID
Set rsOrder = Server.CreateObject("ADODB.Recordset")

rsOrder.Open sqlText, Conn

if rsOrder.EOF then
txtInfo = "This item has been added to your cart."
AddToOrder intOrderID, intProdID, intQuant
else
txtInfo = "This item is already in your cart."
end if

%>

=================================

OR does global.asa file should do anything about this? Please see below:

=============================
' ***** global.asa ****

<script LANGUAGE=VBScript RUNAT=Server>


Sub Application_OnStart


Dim vPath, pPath, ConString

vPath = "database\Prod.mdb"
pPath = Server.MapPath( vPath )

ConString = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & pPath & ";" & "JET OLEDBatabase Password=foo"

Application("visits") = 0
Application("Active") = 0

set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString


dim theMonth, theYear, theDate
dim rs

theYear = right(year(now()), 2)
theMonth = month(now())
theDay = day(now())

if theMonth < 10 then
theMonth = "0" & theMonth
end if

if theday < 10 then
theDay = "0" & theDay
end if

theDate = theYear & theMonth & theDay


sql = "SELECT MAX (orderID) AS theLast FROM orders WHERE Left(orderID, 6) = '" & theDate & "'"
set rsMaxOrder = Server.CreateObject("ADODB.RecordSet")
rsMaxOrder.Open sql, ConString , adLockReadonly

if NOT isNull(rsMaxOrder("theLast")) then
theLast = cInt(right(rsMaxOrder("theLast"), 3)) + 1

if theLast > 999 then
'what do you do here?
else
do while len(theLast) < 3
theLast = "0" & theLast
Loop
end if
else
theLast = "001"
end if

theLast = theDate & theLast


if rsMaxOrder.EOF then
Application("orderID") = theLast
else
Application("orderID") = rsMaxOrder("orderID") + 1
end if
rsMaxOrder.Close
set rsMaxOrder = Nothing

Conn.Close
set Conn = Nothing

End Sub

Sub Session_OnStart
Session("Start") = Now
Application.lock
Application("visits") = Application("visits") + 1
intTotal_visitors = Application("visits")
Application.unlock
Session("VisitorID") = intTotal_visitors


Application.lock
Application("Active") = Application("Active") + 1
Application.unlock
End Sub

Sub Session_OnEnd
Application.lock
Application("Active") = Application("Active") - 1
Application.unlock
End Sub

</SCRIPT>

==============================


please check why this thing happens? thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 30th, 2006, 18:08
Junior Member
Join Date: Jul 2006
Location: Manchester
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Generating ID or Session Problem? Options

Using the application variable probably isn't the best way to do this but I didn't see a specific problem glancing over your code. But it's kind of difficult to look over it on here when it doesn't indent the code and format it.

Typically I'd leave the order number generation up to the database and use either a primary key or a per user order number....e.g. user ID 15 order number two could be 000001500002. This is slightly safer than what you have as you could run into concurrency problems and potentially get two orders with the same number.

You seem to be doing a lot of coding simply to get a unique ID.

My guess would be that this line is not evaluating correctly :
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 21st, 2006, 11:47
Up'n'Coming Member
Join Date: Feb 2004
Location: Woodbridge, UK
Age: 27
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Generating ID or Session Problem? Options

I would def. leave this job up to the database. My companies e-commerce system uses (in simple terms) a table which represents your order header, which has your system generated order number, which is also the basket header (baskets and orders are all the same, it's just basket is one of the orders status', as is paid & dispatched)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
generating, session, problem, options

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Session *not your usual* problem ysamu PHP Forum 0 Mar 28th, 2008 10:00
[SOLVED] Session data problem longstand PHP Forum 15 Dec 9th, 2007 18:28
Session Timeout problem LameesAyman ASP.NET Forum 2 May 2nd, 2007 14:45
session problem fender79 Classic ASP 8 May 18th, 2005 02:26
problem with Session variable andrew_perez5 Classic ASP 0 Jan 24th, 2005 03:42


All times are GMT. The time now is 05:55.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42