Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 16th, 2007, 10:06 AM
Authorized User
 
Join Date: Aug 2006
Location: , NC, USA.
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
Reply With Quote
  #2 (permalink)  
Old March 16th, 2007, 10:51 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:37 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.