Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2007, 10:06 AM
Authorized User
 
Join Date: Aug 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old March 16th, 2007, 10:51 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

from my usage it should always be......
Code:
$query = new CGI;
www.crmpicco.co.uk
www.ie7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
using perl send data via "post" to a php web page robprell Perl 1 May 14th, 2007 05:57 AM
speed up slow Perl code with SQL statements crmpicco Perl 3 May 11th, 2007 05:21 AM
Display text data in textarea from SQL query palvin Classic ASP Professional 13 November 30th, 2005 05:52 PM
Display text data in textarea from SQL query palvin Classic ASP Databases 0 November 29th, 2005 05:44 PM
Porting data from SQL Server to Oracle over ODBC pankaj_daga Oracle 3 August 4th, 2004 05:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.