#!perl
# Fig. 26.20: data.pl
# Program to query a database and send results to the client.

use Win32::ODBC;
use CGI qw( :standard );

$queryString = param( "QUERY" );
$dataSourceName = "Products";

print header, start_html( "Search Results" );

if ( !( $data = new Win32::ODBC( $dataSourceName ) ) )
{
   print "Error connecting to $dataSourceName: ";
   print Win32::ODBC::Error();
   exit;
}

if ( $data->Sql( $queryString ) )
{
   print "SQL failed. Error: ", $data->Error();
   $data->Close();
   exit;
}

print "<FONT FACE = \"ARIAL,SANS-SERIF\" SIZE = 3>";
print "<FONT COLOR = \"BLUE\" SIZE = 4>Search Results</FONT>";
print "<TABLE BORDER = 0 CELLPADDING = 5 CELLSPACING = 0>";

for ( $counter = 0; $data->FetchRow(); $counter++ )
{
   %rowHash = $data->DataHash();
 
   print <<End_Row;
   <TR BGCOLOR = #9999CC>
   <TD>$rowHash{'ID'}</TD>
   <TD>$rowHash{'FirstName'}</TD>
   <TD>$rowHash{'LastName'}</TD>
   <TD>$rowHash{'Phone'}</TD>
   </TR>
End_Row
}

print <<End_Results;
</TABLE>
<BR>Your search yielded <B>$counter</B> results.<BR><BR>
<FONT SIZE = 2>
Please email comments to
<A href = "mailto:deitel\@deitel.com">
Deitel and Associates, Inc.</A>.
End_Results

print end_html;
$data->Close();

########################################################################## 
# (C) Copyright 2001 by Deitel & Associates, Inc. and Prentice Hall.     #
# All Rights Reserved.                                                   #
#                                                                        #
# DISCLAIMER: The authors and publisher of this book have used their     #
# best efforts in preparing the book. These efforts include the          #
# development, research, and testing of the theories and programs        #
# to determine their effectiveness. The authors and publisher make       #
# no warranty of any kind, expressed or implied, with regard to these    #
# programs or to the documentation contained in these books. The authors #
# and publisher shall not be liable in any event for incidental or       #
# consequential damages in connection with, or arising out of, the       #
# furnishing, performance, or use of these programs.                     #
##########################################################################

