You do not need to loop through your records, since you will only be returning 1 record. Therefore check for a record, and if it exists assign it to a variable. If not return a 0 like so:
Code:
Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS.ActiveConnection = objConn
strQ = "SELECT Count(Zipcodes.Zipcode) AS Zipcode FROM Zipcodes where zipcode = '" & strZipcode & "' "
objRS.Open strQ
If objRS.EOF = false then
'we found a match
zipcode_count = objRS("Zipcode")
Else
zipcode_count = 0
End if
objRS.close
objConn.close
Set objRS = Nothing
Set objConn = Nothing
%>
<html>
<body>
<table border="1" cellspacing="1" width="10%">
<tr>
<td width="75%" align="center"><b><font size="2"># of Records that match</font></b></td>
</tr>
<tr>
<td width="25%"><%=zipcode_count%> </td>
</tr>
</table>
One point to remember is ALWAYS check what the user has entered into the textbox before inserting into your database. This will prevent SQL Injection attacks.
Code:
strZipcode = REPLACE(Request.Form("ZipBox"), "'", "''")
You can read more about SQL Injection attacks here:
http://www.sitepoint.com/article/sql...n-attacks-safe
I would also recommend, depending on what type of zipcodes you plan on accepting, check to make sure it's an integer, and limit the size of the textbox.
Your INSERT statment will only execute when the user has submitted your form. Therefore if they do not submit the form, it will not execute and the INSERT statement will not run.
What exact problem are you having with the INSERT statement?
Bookmarks