Forums
This topic is locked
preventing duplicate records
09 Oct 2001 16:07:01 jon badda posted:
A user can order items from a list of products on the site. The item is inserted into an Order table in the DB, possible with other similar entries.If a user already has the same item and tries to order it again, I want them to be taken to an error page.
My problem is that I cant seem to get the code to work where it checks the ProductID against any matches and also checks for matches against the UserID who wants to order it.
The UserID is in a session variable 'svUserID'
any help? it seems pretty simple from where I am, but doesnt want to work.
Replies
Replied 10 Oct 2001 18:54:43
10 Oct 2001 18:54:43 Joel Martinez replied:
if you can't get that code to work... you could try setting the primary key to being the username and productID.
then that way, if you try to insert the same item with the same userid, an error will be thrown. At the top of the page, just include<pre id=code><font face=courier size=2 id=code>on error resume next</font id=code></pre id=code>And at the bottom of the page, or after you execute the insert statement, have a codeblock that looks something like this...<pre id=code><font face=courier size=2 id=code>if err.number <> 0 then
response.redirect("errorpage.asp"
end if</font id=code></pre id=code>that checks for an error, and then redirects if there is one...
Joel Martinez [ ]
----------
E-Commerce Concepts with Ultradev...pre-order yours at
www.basic-ultradev.com/ecomm_concepts/
then that way, if you try to insert the same item with the same userid, an error will be thrown. At the top of the page, just include<pre id=code><font face=courier size=2 id=code>on error resume next</font id=code></pre id=code>And at the bottom of the page, or after you execute the insert statement, have a codeblock that looks something like this...<pre id=code><font face=courier size=2 id=code>if err.number <> 0 then
response.redirect("errorpage.asp"
end if</font id=code></pre id=code>that checks for an error, and then redirects if there is one...
Joel Martinez [ ]
----------
E-Commerce Concepts with Ultradev...pre-order yours at
www.basic-ultradev.com/ecomm_concepts/
Replied 14 Oct 2001 13:31:24
14 Oct 2001 13:31:24 jon badda replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
if you can't get that code to work... you could try setting the primary key to being the username and productID.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
you cant have more than one primary key. at least not with a access database. thanks anyway. i'll see if theres an extension or something
if you can't get that code to work... you could try setting the primary key to being the username and productID.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
you cant have more than one primary key. at least not with a access database. thanks anyway. i'll see if theres an extension or something
Replied 15 Oct 2001 09:46:40
15 Oct 2001 09:46:40 Viktor Farcic replied:
But you can have more than one field with indexed: yes (no duplicates).
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
if you can't get that code to work... you could try setting the primary key to being the username and productID.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
you cant have more than one primary key. at least not with a access database. thanks anyway. i'll see if theres an extension or something
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
if you can't get that code to work... you could try setting the primary key to being the username and productID.
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
you cant have more than one primary key. at least not with a access database. thanks anyway. i'll see if theres an extension or something
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>