How do I get CF to reconize dupicate entries in my database?

fixx17
fixx17 used Ask the Experts™
on
My next project is that I like to know how to get coldfusion to recongnize duplicate entries in my database.

Now I have a page that will query the database by entering in the Asset Tag Number and then it will <CFOUTPUT> the information.

And I have another page with a form that will insert information to the database.

What I want is when someone tries to add to the ASSETTAG Number to the database, it will catch a duplicate ASSETTAG Number and send the person off to another page not allowing them to enter this information and diplaying a message like " Asset Already entered."


Can any point me in the right direction?

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
i know you're using Access so a simple thing to do is to go to the access db and make that column unique, i mean that no duplicate entries could be exist

Author

Commented:
Ok, I found it in Design View.  But what would happen now if I try to add an entry on the net and Access would not allow this.  Would I get an error thrown at me?

Commented:
Of Course.  That is why you would usually have a <cftry>

<cftry>
  <cfquery>
    ....
  </cfquery>

<cfcatch type="database">
   There was an error.
   
   Message: #CFCATCH.message#
   Detail: #CFCATCH.detail#
   Exception Type: #CFCATCH.TYPE#
</cfcatch>
</cftry>

It will not work, but now you could explain in "english" why it failed.  Or not explain at all.
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Commented:
dummy page

<script language="JavaScript">
   function fnRedirect(count){
      if ( count> 0 ){
           document.frmDummy.action = "error.cfm"
     
      }else{
        document.frmDummy.action = "insert.cfm"
      }
    document.frmDummy.method = "post"
    document.frmDummy.submit()
   }
</script>



<cfquery name="check2exit" datasource="dsn">
   select count(*) rec_count from table
   where Asset Tag Number = #form.assettagno#  
</cfquery>

<cfset reccount = 0>  
<cfloop query="check2exit">
   <cfset reccount = rec_count>  
</cfloop>

<body <cfoutput>onload="fnRedirect('#reccount#')</cfoutput>>
<form name="frmDummy">
<cfoutput>
  <input type="hidden" name="assettagno" value="#form.assettagno#">
  <!--- carry all the variable in the hidden variable as it need in insert page --->

</cfoutput>
</form>
<body>

error.cfm
----

show this tag name already exit.


insert.cfm
---

do the needful to insert the data into databse with user input.

Author

Commented:
OK, trying to understand what is going on here.  Give me some time and I will get back to you.


Author

Commented:
Thanks, this did work, I just needed to change some parameters.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial