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

Create a Unique ID

Status
Not open for further replies.

ggrewe

IS-IT--Management
Jul 10, 2001
169
US
I am creating (bascially) an online order form and I want to be able to display a unique confirmation number on a confirmation page. I can create a unique number in the database, but I do not know how to display that same record as a confirmation page, since I do not know the record number when it is inserted. So my thought was to have the ASP page create a unique number before it inserts into the database and assign the value to a hidden field. I was thinking along the lines of a Julian date and the seconds since midnight, or something. But I do not know how to do that in ASP. Any suggestions?

Thanks,

Greg
 
I wouldn't do that option since more than one person could submit an order at the same time and since the processor works much faster than seconds, it could enter it with the same ID.

One way you could do it is have the person submitting the form be a member of the site to order (usually the case anyway), and they have their own unique identifier number (PK) in the member table of the database. Then have a seperate table for the orders, one with a memberFK (foreign key) which will have the ID of the member to link them to that order. Therefore, when you go to the confirmation page, you just run a check for all the orders they've made (or maybe just the most recent one with the option to retrieve all of their info) and display it.

Does that make sense? Should work nicely I think.
-Ovatvvon :-Q
 
Thanks Ovatvvon, but in thise case not everyone will be an existing member, in fact most will not. That is why I am trying to come up with a way to generate a unique number on the asp side, not on the db side.

Greg
 
If you're using SQL Server, then the best way to do this is to use a stored procedure to INSERT the record... Once you do that, you can just ask for:

SELECT @@identity FROM inserted

from inside the stored procedure, and assign that value to an output parameter, which you can then grab on the page and put in your hidden field. If you're not using SQL Server, then search for @@identity in your Access stuff or even over in the Access forum on this site. I know I have heard ppl talk about it, so there is a way to get the value.

hope that helps. :)
Paul Prewett
penny.gif
penny.gif
 
If a random string is the same ...

Randomize
strRndValue = chr (int( 20 * Rnd +65 )) & int ( 9999 * Rnd + 1) & chr (int( 20 * Rnd +65 )) & chr (int( 20 * Rnd +65 ))
 
I did something sort of in this vein awhile ago...but I needed to generated unique and somewhat sequential confirmation #'s...which would be used as the filenames for new text files created on the server, after which I would just have a script tack on ".asp" and then run.

I used the function of time, as you indicated:

<%
' CREATE A UNIQUE FILENAME
Dim timeStamp, number, strFileName, savedFileName, choice
timestamp = FormatNumber(Now(),5,0,0,0)
strFileName = CStr(timeStamp)
savedFileName = &quot;M&quot; & strFileName & &quot;.asp&quot;
choice = Request.Form(&quot;choice&quot;)
%>
...this was a rather crude method...it worked, but left a decimal point and remainders since the VBScript Now() function was converting the datetime value to a string.
 
I did something sort of in this vein awhile ago...but I needed to generated unique and somewhat sequential confirmation #'s...which would be used as the filenames for new text files created on the server, after which I would just have a script tack on &quot;.asp&quot; and then run.

I used the function of time, as you indicated:

<%
' CREATE A UNIQUE FILENAME
Dim timeStamp, number, strFileName, savedFileName, choice
timestamp = FormatNumber(Now(),5,0,0,0)
strFileName = CStr(timeStamp)
savedFileName = &quot;M&quot; & strFileName & &quot;.asp&quot;
choice = Request.Form(&quot;choice&quot;)
%>
...this was a rather crude method...it worked, but left a decimal point and remainders since the VBScript Now() function was converting the datetime value to a string.

Just a thought on some options.
 
You could also just use the persons session id as the unique number and then just insert that into your database.

Roj
 
Perhaps an asp derived unique identifier would work fine, but I personally don't see it as practical for a business...(I could be wrong though).

I think it would be better to let the database control the identifier...if it's finding that id that is the problem, and if you don't want to create two tables to include members but have the orders available to anonymous buyers, then another thing you could do is while having the order stamped with the now() function to show the time of purchase, after you insert the order into the database run a search on the same asp page that inserted them right after for the record that matches this time variable that equaled the now() value of when it was ordered.

To make sure you distinguish between two or more possible orders that could've been made at the same time, also use the variables inserted into the db and run a match for them such as address, city, state, zip, first and last names, etc.


timeOrdered = now()

sql = &quot;INSERT INTO myTable (mytable_info) VALUES ('&quot; & allOfMyInfo & &quot;');

sql = &quot;SELECT * FROM myTable WHERE ((myTable.orderTime)='&quot; & timeOrdered & &quot;') AND ((myTable.userFirst)='&quot; & firstName & &quot;') AND ((myTable.userLast)='&quot; & lastName & &quot;') AND ((myTable.userCity)='&quot; & theirCity & &quot;');&quot; ...etc

orderID = rs(&quot;autoNumberGenerated&quot;)


This was brief, but again I think using this approach will work more accurately and more efficiently. Take it for what it's worth.
-Ovatvvon :-Q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top