OutFront Forums
     Home    Register     Search      Help      Login    

Sponsors
Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax
Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.
Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Follow Us
On Facebook
On Twitter
RSS
Via Email

Recent Posts
Todays Posts
Most Active posts
Posts since last visit
My Recent Posts
Mark posts read

 

Check for existing record before submit

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP, PHP, and Database >> Check for existing record before submit
Page: [1]
 
 
Joey

 

Posts: 188
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: 1741
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

(in reply to Joey)
Joey

 

Posts: 188
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.

(in reply to ou812)
ou812

 

Posts: 1741
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

(in reply to Joey)
Joey

 

Posts: 188
Joined: 5/15/2002
From:
Status: offline

 
RE: Check for existing record before submit - 4/11/2009 22:36:39   
Perfect, thank you.

(in reply to ou812)
Page:   [1]

All Forums >> Web Development >> ASP, PHP, and Database >> Check for existing record before submit
Page: [1]
Jump to: 1





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