in reply to Re: •Re: Method "do" error
in thread Method "do" error

I think merlyn has already provided the answer. In the store_items subroutine, simply remove this line:

  my $dbh;

From your description of WebDB, it seems likely that it is creating a DBI database handle object and storing it in a global variable called '$dbh'. By including 'my $dbh;' in the subroutine, you are creating a new variable with the same name that only exists within the subroutine and prevents access to the global. Because the variable in the subroutine is new, it is undefined.

Since you have 'use strict' in effect, it is possible that removing the my $dbh; line will trigger the error: Global symbol "$dbh" requires explicit package name. If that is the case, you'll need to explicitly declare that it is a global variable like this:

  our $dbh;

Replies are listed 'Best First'.
Re: Re: Re: •Re: Method "do" error
by b310 (Scribe) on Apr 20, 2003 at 20:30 UTC
    Hi,

    I tried your suggestion.

    First, I did remove the $dbh from the subrouting and received an internal server error message.
    Secondly, I also change my $dbh to our $dbh in hopes that would solve the problem. I received the same internal server error message.

    I included the modified code. Any other ideas or thoughts?

    #! /usr/local/bin/perl -Tw use strict; use lib qw(/usr163/home/w/s/wstrader/public_html/library); use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard escape escapeHTML); use WebDB; our $dbh = WebDB::connect (); my $name = param("name"); my $coname = param("coname"); my $phone = param("phone"); my $email = param("email"); my $address = param("address"); my $city = param("city"); my $state = param("state"); my $zip = param("zip"); my $country = param("country"); my $page; my $choice = lc (param ("choice")); if ($choice eq "submit") # information submitted via form { store_items (); } else { $page .= p (escapeHTML ("Logic error, unknown choice: $choice")); } sub store_items { $dbh->do ("INSERT INTO contact_info (contact_date,contact_name,company,telephone,email,addre +ss,city,state,zip_code,country) VALUES (CURRENT_DATE,?,?,?,?,?,?,?,?,?)", undef, $name, $coname, $phone, $email, $address, $city, $state, $zip, $country); $dbh->disconnect(); }
      If WebDB::connect is returning a DBI object, print it out.

      our $dbh = WebDB::connect() || die "Ohh no $!\n";; use Data::Dumper; print Dumper $dbh;

      You should see a hash structure that is blessed as a DBI object.

      grep
      Mynd you, mønk bites Kan be pretti nasti...

      I did remove the $dbh from the subrouting and received an internal server error message.

      You need to track down the text of the Perl error which is causing the script to fail and which in turn is causing the web server to display the 'server error' page.

      The use CGI::Carp qw(fatalsToBrowser); line you already have should cause the Perl error to be passed to your browser but for some reason that's not happening. Can you get access to the web server's error log file? Or, can you run your script from the command line so the error message come to your terminal window?