ODBC in Perl to display SQL data?
Hi, I am stumped - new Perl user. . .
I am using the standard HTML form page for people to submit a name to search one name field called panelist1 in our SQL db (would like it to be multiple fields since there are 9 name fields there). If the search comes up with a name close or matching to the user's search terms, I want to display back on the web that panelist's name, the Title (another field) and the broadcastDate (another field). The problem is when I try to run this, I keep getting that pesky "CGI error: The specified CGI application misbehaved by not returning a complete set of HTTP headers."
I tried: 1.) Running this at the MS-DOS command prompt at the server and got "use of unitialized value in string eq at line 12" - referring to this line:
if ($query->request_method() eq "POST")
Not sure what it is looking for?
2.) Inserting different headers, like the standard
print "Content-type: text/html\n\n";
but this didn't change the CGI error.
So here is the coding for the Perl script, called search.pl :
#!c:\perl\bin\perl.exe
use CGI;
use DBI;
$query = CGI::new();
print $query->header();
print $query->start_html(
-title=>'Search Broadcasts by Presenter',
-bgcolor=>'#FFFFFF');
if ($query->request_method() eq "POST")
{
&ProcessForm;
}
else
{
&PrintForm;
}
print $query->end_html();
sub ProcessForm # * Begin ProcessForm SubRoutine *
{
$searchname = $query->param("panelist1");
# $sql = "SELECT * FROM Teleconferences WHERE panelist1 ='$searchname';";
# or
$sql = "SELECT * FROM Teleconferences WHERE panelist1 LIKE \'%$searchname%\';";
$dbh = DBI->connect('dbi:odbc:OURweb', '', '', ,
{ RaiseError => 1 });
$cursor = $dbh->prepare($sql);
$cursor->execute;
print "<H2>Search Results</H2>";
print "You searched for: <B>$searchname</B><BR>";
while (@row = $cursor->fetchrow_array)
{
push @panelist1, $row[0];
push @Title, $row[1];
push @broadcastDate, $row[2];
}
if (scalar(@panelist1))
{
print "<TABLE BORDER=1><BR>";
print "<TR><TH>Panelist<TH>Title<TH>Broadcast Date<BR>";
for ($i=0; $i<scalar(@panelist1); $i++)
{
print "<tr><td align=right>$panelist1[$i]";
print "<td align=left>$Title[$i]";
print "<td align=right>$broadcastDate[$i]";
}
print "</TABLE>";
print "<A HREF='search.pl'>Return to the search page</A><br>";
}
else
{
print "No records found for \"$searchname\".<p>";
print '<a href="search.pl">Return to the search page</a>';
}
$dbh->disconnect;
} # *** End ProcessForm ***
sub PrintForm # *** Begin PrintForm SubRoutine ***
{
print <<ENDOFTEXT;
<FORM METHOD="POST" ACTION="search.pl">
<H2> Search Broadcasts by Presenter</H2>
Enter the name of the presenter you wish to search for: <BR>
<INPUT NAME="searchname">
<INPUT TYPE=SUBMIT><BR>
</FORM>
ENDOFTEXT
} # *** END PrintForm ***
Any advice, clues or hints would be appreciated! Thanks.
-Buddy
|