|
| |
|
|
Joey
Posts: 187 Joined: 5/15/2002 From: Status: offline
|
Check for existing record before submit - 4/11/2009 20:36:55
I need to check the database to see if the record exists before the form adds a new record. What is the best method for doing this?
|
|
|
|
ou812
Posts: 1705 Joined: 1/5/2002 From: San Diego Status: offline
|
RE: Check for existing record before submit - 4/11/2009 21:26:10
Not sure if this is the best method but I usually just select count to see if it is there. Something like Select count(*) as howmany from tablename where columnname = "Some Name" Then check the variable howmany to see if it is 0 or not.
_____________________________
-brian Black Holes suck. EnterpriseDB: Enterprise-class relational database management system PostgreSQL: The world's most advanced open source database
|
|
|
|
Joey
Posts: 187 Joined: 5/15/2002 From: Status: offline
|
RE: Check for existing record before submit - 4/11/2009 21:31:23
Maybe I didnt explain it very well. I have a registration form where a user can pick their username. before the record is added I need to check to make sure the username is not in use and if it does return an error message but not submit the record.
|
|
|
|
ou812
Posts: 1705 Joined: 1/5/2002 From: San Diego Status: offline
|
RE: Check for existing record before submit - 4/11/2009 22:32:57
I think I would do the same thing, if I understand you correctly. And going with your example, something like this on the posted page - Select count(*) as howmany from users where username = request.form(user_name) If howmany > 0 then ' means this user name already exists response.redirect("user_entry_form.asp?exists=YES") end if ' Continue on since this user isn't already entered You can return a few different ways. I'm using an example with a return querystring. So, in your calling page, user_entry_form.asp as the example shows, you would need to have something checking for the request.querystring("exists") and if so, display an error message. Meaning, if that variable has something in it, specifically YES, then it is being returned from your processing page, and you can display an error on that page stating the username is already there. You can make the querystring longer to include the username, or set a session variable and perform the same type of task. Does that help?
_____________________________
-brian Black Holes suck. EnterpriseDB: Enterprise-class relational database management system PostgreSQL: The world's most advanced open source database
|
|
|
|
Joey
Posts: 187 Joined: 5/15/2002 From: Status: offline
|
RE: Check for existing record before submit - 4/11/2009 22:36:39
Perfect, thank you.
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|