Home
About
Contact
Categories
Classic ASP (32 - Entries)
CSS (1 - Entry)
JavaScript (5 - Entries)
Databases (30 - Entries)
ASP.NET (26 - Entries)
Delphi (6 - Entries)
Windows Server Core (13 - Entries)
VMWare (1 - Entry)
Code Editing Tools (2 - Entries)
Linux (4 - Entries)
Dell Servers (15 - Entries)
Design and Editing Software (1 - Entry)
Blog Entries
2025 (3 - Entries)
Bug Reports
(Bugs Fixed
CFFCS Coding Source
Please report any errors to the [
Contact
] page. Thank you.
Classic ASP (32)
CSS (1)
JavaScript (5)
Databases (30)
ASP.NET (26)
Delphi (6)
Windows Server Core (13)
VMWare (1)
Code Editing Tools (2)
Linux (4)
Dell Servers (15)
Design and Editing Software (1)
Tools
Format Your SQL Script
Minify your CSS
Resources
[View The Source Code For This Project]
Classic ASP
Forms
ASP Classic check if Zip Code exists, if not show message
Live Editing Disabled for Server-Side Example
HTML
Main.asp
<% ' Designed By Wayne Barron aka Carrzkiss ' Dated: 07/07/2011 ' ASP Classic with Access Database connection ' This demonstration shows how to test a form field value against the database. ' If the value exists in the database, then display a message. ' If the value does not exist, then display a "does not exist" message. ' For more examples, go to www.cffcs.com. ' Date: 07-30-2022 - Name changed of Function from ProtectSQL to ' ProtectXSS, as it was brought to my attention that saying SQL was ' misleading. chZip = ProtectXSS(Request.Form("Zip")) %>
Zip Code Check
<%if request.form("Submit")="Check Zip Code" then ' Added 07/23/2022 ' Check if the value passed is a number value. If not, show a message. if not IsNumeric(chZip) then response.Write "Not a valid number, please enter a Zip Code." else '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
not
in the database" else ' If the zip code exists, then send them to the zip page 'response.redirect"Q_27183114.asp" 'Or, if you want to display a message %> Your zip code <%=rsZip("Zip")%> is in the database
City = <%=rsZip("City")%>
State = <%=rsZip("State")%>
County = <%=rsZip("County")%> <% end if ' Ends, check for Record Set. end if ' Ends, check if Number sent. end if ' Ends, check for Submit button value.%>
Classic ASP
ACN.asp
ProtectXSS.asp
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% siteurl = "192.168.2.12/cs" 'Change the URL to your URL getServer = "sqlcorecs-01" ' Change to your Server Name getInstance = "sql2019" ' Change to your SQL Server instance Name getID = "testuser" ' Change to your SQL Server Username getPW = "testuser" ' Change to your SQL Server Password Set objConn = CreateObject("ADODB.Connection") objConn.Open("Provider=SQLOLEDB; Data Source="&getServer&"\"&getInstance&"; Initial Catalog=Virtual-Class-01;User ID="&getID&";Password="&getPW&";") %>
<% Function ProtectXSS(SqlString) SqlString = Replace(SqlString, "'", "'") ' replace single Quotes with Double Quotes SqlString = Replace(SqlString, ">", ">") ' replace > with > SqlString = Replace(SqlString, "<", "<") ' replace < with < SqlString = Replace(SqlString, "(", "(") ' replace ( with ( SqlString = Replace(SqlString, ")", ")") ' replace ) with ) SqlString = Trim(SqlString) ProtectXSS = SqlString End Function %>
Preview
Tags
Zip Code lookup form
In An ASP Classic US Zip Code lookup form
In An ASP Classic US Zip Code lookup form
protect our database from XSS and SQL Injection
protect our database from XSS and SQL Injection
protect our database from XSS and SQL Injection
protect our database from XSS
protect our database from SQL Injection
protect our database from SQL Injection
protect our database from SQL Injection
SQL Injection
XSS Injection
ProtectSQL
ProtectXSS
ASP Classic Protect against SQL Injection
ASP Classic Protect against XSS Attacks
ASP Classic Parameterized Queries