another form validation question

Results 1 to 4 of 4

Thread: another form validation question

  1. #1
    Matt1999 Guest

    Default another form validation question

    How would you search a database and display an error if the record already exists?<BR><BR>I have a database where people can enter their user name and password. When a user tries to submit a user name that already exits, I would like to display text stating "That user name already exists", instead of an error like:<BR><BR>[Microsoft][ODBC Microsoft Access Driver] The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again. <BR><BR><BR>What is a simple way of checking the database and then displaying the error message? Thanks!<BR>

  2. #2

    Default RE: another form validation question

    Create a stored procedure which takes input parameters e.g. forename, surname and explicitly queries our table and returns a count of records matching.<BR><BR>whenever a user passes data via the form, run the Stored procedure - if it returns 0, proceed to insert a record, otherwise write out an error that the record with the username details already exists

  3. #3
    Join Date
    Dec 1969

    Default You can try this

    after making the connection, first query the database for the user name that the user has given.<BR><BR>qry = "select username, pass from tablename where username = &#039;" & request("username") & "&#039;"<BR><BR>set rs = conn.execute(qry)<BR>if not rs.eof then<BR>response.write "username exists"<BR>else<BR>&#039; insert the record here<BR>end if

  4. #4
    Matt1999 Guest

    Default RE: You can try this

    Thanks Vineet, that worked!

Posting Permissions

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