Go Back To List
Queries Against Access Database
ASP Classic check if Zip Code exist, if not show message.
Next Article
Microsoft Access Database Queries and Relationships
Coding Article #: 21 - Published On: July 07, 2011 @ 14:58:47 PM - Last Updated on: July 13, 2012
This article has been Favorited 19 times
Join today, and add this to your favorites.
Coding Source - Share on MySpace Coding Source - Share With Facebook Coding Source - Share on Twitter Coding Source - Share on Reddit Coding Source - Share on Digg It Coding Source - Share on Stumble Upon It Coding Source - Share on Delicious
Share With Friends (Updated 6-8-2010)

Supported Files
File Download:
carrzkiss_030615Q_27183114.zip
File Size: 620.1 KB
Unzip with
Download winzip today!(OR)
Screenshot of Source Code
Coding Source - ASP Classic check if Zip Code exist, if not show message.
In this example, we are going to be using [ASP Classic] and an [Access Database].
When the user enters their Zip Code into the form, we will do the following.
#1: Use a function that will protect our database from [XSS] and [SQL Injection]called: [ProtectSQL]
#2: Check the value from the form against our database.
#3: If the Zip Code [Does exist], we will display a message to the user letting them know that the Zip Code exist
#4: If the Zip Code [Does not exist], we will display a message letting them know that it does not exist.

The database comes with over 5,000 Zip Code entries, it well update it soon with all the zip codes in the USA.

View Demo Page«

First, we will add to the top of our page, the request.Form("Zip"), this will allow it to be used throughout the page.
(You will need to downloadable file, to get the rest of the code, from the ACN.asp file, which has the included ProtectSQL() function.)

<%
chZip = ProtectSQL(Request.Form("Zip"))
%>



Second, we need our form.

<form action="Q_27183114.asp" method="post">
<input type="text" name="Zip" value="<%=chZip%>" />
<input type="Submit" name="Submit" value="Check Zip Code" />
</form>


Next, we need to check for the form rather it has been submitted or not.
If it has, we will process the

<%if request.form("Submit")="Check Zip Code" then
'Now, the ASP part of it.
'First we need to check the database
'Get our form value
Set sql = Server.CreateObject("ADODB.Command")
sql.ActiveConnection=objConn ' Check out connection
sql.Prepared = true
sql.commandtext="Select zip, city, state, county from ZipTable where Zip=?"
sql.Parameters.Append sql.CreateParameter("@Zip", 200, 1, 255, chZip)
set rsZip = sql.execute
if rsZip.eof then
' Use either redirect or write
'response.redirect"page.asp"
response.write"Your zip code "&chZip&" is <strong>not</strong> in the database"
else ' If the zip code exist, then send them to the zip page
'response.redirect"Q_27183114.asp"
'Or, if your want to display a message
%>
Your zip code <%=rsZip("Zip")%> is in the database<br />
City = <%=rsZip("City")%><br />
State = <%=rsZip("State")%><br />
County = <%=rsZip("County")%>
<%
end if
end if%>
Post to Facebook about: ASP Classic check if Zip Code exist, if not show message.