Zip2Tax Logo

Developers Information

Database Link (developers information)

Each Database Link customer is assigned a Microsoft SQL Server Stored Procedure that is custom made to accomodate the customer's exacting specifications. Connecting through this method assures the quickest possible reponse time. There are a variety of methods available to make this connection using common languages found in web development.

Direct Connect using ASP

<%

strServer = "db.Zip2Tax.com"
strUsername = "z2t_Sample"
strDBPassword = "db_pwd"
strDatabase = "zip2tax"

'Open the connection
Set conn=server.CreateObject("ADODB.Connection")
conn.Open "driver=SQL Server;server=" & strServer & ";uid=" & strUsername & ";pwd=" & strDBPassword & ";database=" & strDatabase

'Assign values to the input variables
strZipCode = "90210" : 'sample zip code must be between 90001 and 92999
strPassword = "user_pwd"

'Open the recordset using the stored procedure
Set rs = server.CreateObject("ADODB.Recordset")
rs.open "z2t_lookup_sample('" & strZipCode & "', '" & strPassword & "')", conn, 3, 3, 4

'Read the results
If not rs.EOF then
    Response.write "Zip Code: " & rs("Zip_Code")
    Response.write "Sales Tax Rate: " & rs("Sales_Tax_Rate")
    Response.write "Post Office City: " & rs("Post_Office_City")
    Response.write "County: " & rs("County")
    Response.write "State: " & rs("State")
End If

'Close the Database
rs.Close
conn.Close

%>

Direct Connect Using PHP

<?php

$strServer = "db.Zip2Tax.com";
$strUsername = "z2t_sample";
$strDBPassword = "db_pwd";
$strDatabase = "zip2tax";

//Open the connection
$conn = @mssql_connect($strServer, $strUsername, $strDBPassword)
    or die("Couldn't connect to SQL Server on $strServer");

//Open the Database
$d = @mssql_select_db($strDatabase, $conn)
    or die("Couldn't open database $strDatabase");

//Set-up the Query
$query = mssql_init("z2t_lookup_Sample", $conn);

$strZipCode = "90210"; //sample zip code must be between 90001 and 92999
$strUserPassword = "user_pwd";

mssql_bind($query, "@zipcode", &$strZipCode, SQLVARCHAR);
mssql_bind($query, "@pwd", &$strUserPassword, SQLVARCHAR);

//Execute the query
$result = mssql_execute($query);

//Read the result
while($row = mssql_fetch_array($result))
    {
    echo "Zip Code: " . $row['Zip_Code'] . "<br>";
    echo "Sales Tax Rate: " . $row['Sales_Tax_Rate'] . "<br>";
    echo "Post Office City: " . $row['Post_Office_City'] . "<br>";
    echo "County: " . $row['County'] . "<br>";
    echo "State: " . $row['State'] . "<br>";
    }

//Close the Database
mssql_close($conn);

?>

Passing Request Variables

Another method of pulling information from our database is to incorporate request variables.

Quick Link

The simpliest form of this method is to click on the link below (use the browser's back button to return to here).

http://www.zip2tax.com/Link/Lookup_Sample.asp?zip=90210&pwd=user_pwd

Or you can paste this line of code into any browser's URL box.

You will see that you looked up the data using the request variables. You may wish to try other zip codes (between 90001 and 92999) to see the results.

Return the Results in a Useful Format

Now we want to have the results passed back to us in a useful format. At the end of the URL we are going to add a return request variable as shown.

http://www.zip2tax.com/Link/Lookup_Sample.asp?zip=90210&pwd=user_pwd&ret=http://www.Zip2Tax.com/Link/DisplayResults.asp

Instead of displaying the results directly to the browser as in the Quick Link example, the data is being passed to a separate page using request variables and the new page is displaying the data. This new page should reside on your server and can be written in any language.

Display Request Variable Results Using ASP

This is a separate asp page.<br><br>

Zip_Code: <%=Request("Zip_Code")%><br>
Sales_Tax_Rate: <%=Request("Sales_Tax_Rate")%><br>
Post_Office_City: <%=Request("Post_Office_City")%><br>
County: <%=Request("County")%><br>
State: <%=Request("State")%><br>

Display Request Variable Results Using PHP

<?php

echo('This is a separate php page.<br><br>');

echo('Zip_Code: ');
echo($_REQUEST['Zip_Code'].'<br>');

echo('Sales_Tax_Rate: ');
echo($_REQUEST['Sales_Tax_Rate'].'<br>');

echo('Post_Office_City: ');
echo($_REQUEST['Post_Office_City'].'<br>');

echo('County: ');
echo($_REQUEST['County'].'<br>');

echo('State: ');
echo($_REQUEST['State'].'<br>');

?>