Checking database

Results 1 to 2 of 2

Thread: Checking database

  1. #1
    Join Date
    Dec 1969

    Default Checking database

    My question is that I have a customer table which contains customer id and name. In my asp, i want to let users to add new customer. When users submit the form, I want to check to see if the customer id entered by users already exists in my database...<BR><BR>The problem is that I open a recordset in asp(&#060;% & %&#062;), but the checking procedure is written in vbscript.... I can&#039t pass the whole recordset to the vbscript sub....

  2. #2
    Join Date
    Dec 1969

    Default Trying to interpret that...

    By default, ASP code (&#060;%...%&#062;) *is* written in VBScript. So why doesn&#039t your checking code work, when you say it (too) is written in VBScript?<BR><BR>AS A GUESS...I would bet that what you mean is that your checking procedure is designed to be a *BROWSER* script, possibly used as part of form validation???<BR><BR>If I guessed right, then the short answer is: You can&#039t do it that way.<BR><BR>Browser-side code can&#039t call server-side code. Period.<BR><BR>So you need to change this piece of your code to do the checking in ASP. And then it&#039s pretty easy:<BR><BR>&#060;%<BR>newCustID = Request.Form("customerID")<BR>... create and open your DB connection ...<BR>&#039 omit the &#039...&#039 characters in next line if customerID in DB table is numeric<BR>Set RS = yourConnection.Execute("SELECT * FROM table WHERE customerID=&#039" & newCustID & "&#039")<BR><BR>If Not RS.EOF Then<BR>&nbsp; &nbsp; Response.Write "Sorry! That customer ID is already in use! Try again!"<BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; Response.End<BR>End If<BR><BR>&#039 add the new customer<BR>...<BR>%&#062;<BR><BR>But...may I ask: Why do you let the USER select the customer ID? Why don&#039t you just assign it automatically? Of course, if you do that, you would still probably want to check for duplicate customers, but now presumably you could do that based on their zip code and last name or something similar.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts