Professional Web Applications Themes

"Can't call method "disconnect" on an undefined value..." - PERL Modules

Hey there anyone, I am new at this and I am trying to figure this out and I don't know too much, but I keep getting this error when trying to run my cgi page can anyone help, please. Here is the error: Can't call method "disconnect" on an undefined value at /home/virtual/site7/fst/var/www/cgi-bin/affiliates/common.sub line 44. Here is the script I am trying to run: #!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); #!/usr/local/bin/perl -w ################## Form Processing Function ######### if ($ENV{'REQUEST_METHOD'} eq 'GET') { # Split the name-value pairs pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { # Get the input read(STDIN, ...

  1. #1

    Default "Can't call method "disconnect" on an undefined value..."

    Hey there anyone,

    I am new at this and I am trying to figure this out and I don't know
    too much, but I keep getting this error when trying to run my cgi page
    can anyone help, please.

    Here is the error:

    Can't call method "disconnect" on an undefined value at
    /home/virtual/site7/fst/var/www/cgi-bin/affiliates/common.sub line 44.

    Here is the script I am trying to run:

    #!/usr/bin/perl

    use CGI::Carp qw(fatalsToBrowser);
    #!/usr/local/bin/perl -w

    ################## Form Processing Function #########

    if ($ENV{'REQUEST_METHOD'} eq 'GET') {
    # Split the name-value pairs
    pairs = split(/&/, $ENV{'QUERY_STRING'});
    }
    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
    # Get the input
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

    # Split the name-value pairs
    pairs = split(/&/, $buffer);
    }
    foreach $pair (pairs) {

    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $value =~ s/<([^>]|\n)*>//g;
    $value =~ s/\<//g;
    $value =~ s/\>//g;
    $value =~ s/\|//g;
    $value =~ s/\*/\\\*/g;
    $value =~ s/\?/\\\?/g;
    $value =~ s/\+/\\\+/g;
    $FORM{$name} = $value;
    }

    #require "/var/www/cgi-bin/affiliates/config.cgi"; # you might need
    the full path to this file
    require "/home/virtual/site7/fst/var/www/cgi-bin/affiliates/config.cgi";
    # you might need the full path to this file
    require "/home/virtual/site7/fst/var/www/cgi-bin/affiliates/common.sub";
    # you might need the full path to this file
    use CGI;
    use CGI qw(param);
    use CGI qw/:standard/;

    $q = new CGI;

    $ip = $q->remote_host();

    stuff = $q->param;
    foreach $stuff (stuff) {${$stuff} = $q->param($stuff);}

    &gettheaffiliate;



    sub gettheaffiliate {

    $getcookie = $q->cookie($cookiename);
    if ($getcookie) {}
    else {
    &Create_DB_Connection;
    $SQL="SELECT * FROM hits WHERE Ip='$ip'";
    &Do_SQL;
    while ($pointer = $sth->fetchrow_hashref){
    $getcookie = $pointer->{'Id'};
    }
    $sth->finish;
    $dbh->disconnect;
    }
    }
    if ($getcookie ne ''){$getcookie = "Affiliate: $getcookie"}


    $quantity = $FORM{'Quantity'};
    $price = '54.95';
    $shipping = $FORM{'s'};


    $sub_shipping = sprintf("%.2f", $shipping * $quantity);
    $sub_price = sprintf("%.2f", $price * $quantity);
    $sub_total = sprintf("%.2f", $sub_price + $sub_shipping);
    $amount = sprintf("%.2f", $sub_price + $sub_shipping);

    if ($FORM{s} eq '8.95'){ $ship = 'Shipping: Ground';}
    if ($FORM{s} eq '21.95'){ $ship = 'Shipping: Rush';}
    if ($FORM{s} eq '26.95'){ $ship = 'Shipping: Canada';}
    if ($FORM{s} eq '33.95'){ $ship = 'Shipping: International';}






    &returnhtml;
    #$amount = '39.95';


    #use CGI::Carp qw(fatalsToBrowser);
    #use CGI qw (:standard);
    #$q = new CGI;
    #$cashflow = $amount; #where the $amount is whatever variable contains
    the final purchase price.
    #require "/home/hostcrew/hostcrew-www/cgi-bin/affiliates/config.cgi";
    #require "/home/hostcrew/hostcrew-www/cgi-bin/affiliates/common.sub";
    #require "/home/hostcrew/hostcrew-www/cgi-bin/affiliates/sale.cgi";
    #&salecommission;
    #exit;

    I hope someone can help, Thank You in advanced!

    Justin
    Metalbomer Guest

  2. #2

    Default Re: "Can't call method "disconnect" on an undefined value..."

    Metalbomer wrote:
    > I am new at this and I am trying to figure this out and I don't know
    > too much, but I keep getting this error when trying to run my cgi page
    > can anyone help, please.
    >
    > Here is the error:
    >
    > Can't call method "disconnect" on an undefined value at
    > /home/virtual/site7/fst/var/www/cgi-bin/affiliates/common.sub line 44.
    As the error message says, the value is undefined -- without counting lines
    in your code, I suspect it's the line $dbh->disconnect, which would hint at
    the fact that allocating the database handle may have failed and you should
    have checked that error condition there. If you expect $dbh to sometimes be
    undefined, $dbh->disconnect if ($dbh) would help.

    --
    Klaus Johannes Rusch
    [email]KlausRuschatmedia.net[/email]
    [url]http://www.atmedia.net/KlausRusch/[/url]


    Klaus Johannes Rusch Guest

  3. #3

    Default Re: "Can't call method "disconnect" on an undefined value..."

    Klaus Johannes Rusch <KlausRuschatmedia.net> wrote in message news:<3F01693B.3EC7CD61atmedia.net>...
    > Metalbomer wrote:
    >
    > > I am new at this and I am trying to figure this out and I don't know
    > > too much, but I keep getting this error when trying to run my cgi page
    > > can anyone help, please.
    > >
    > > Here is the error:
    > >
    > > Can't call method "disconnect" on an undefined value at
    > > /home/virtual/site7/fst/var/www/cgi-bin/affiliates/common.sub line 44.
    >
    > As the error message says, the value is undefined -- without counting lines
    > in your code, I suspect it's the line $dbh->disconnect, which would hint at
    > the fact that allocating the database handle may have failed and you should
    > have checked that error condition there. If you expect $dbh to sometimes be
    > undefined, $dbh->disconnect if ($dbh) would help.
    That would fine I understood that but the line that errors out is blank. Look here:

    (LINE 43)$ip = $q->remote_host();
    (LINE 44)
    (LINE 45)stuff = $q->param;
    (LINE 46)foreach $stuff (stuff) {${$stuff} = $q->param($stuff);}

    That is my problem and also as to why I don't understand the error message.
    Metalbomer Guest

  4. #4

    Default Re: "Can't call method "disconnect" on an undefined value..."

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    [email]Metalbomer1hotmail.com[/email] (Metalbomer) wrote in
    news:18b2b862.0306300932.50e9f7aeposting.google.c om:
    > Hey there anyone,
    >
    > I am new at this and I am trying to figure this out and I don't know
    > too much, but I keep getting this error when trying to run my cgi page
    > can anyone help, please.
    Here's a nickel's worth of free advice: Toss this script, and never
    return to wherever you got it. It's crap.

    > Here is the error:
    >
    > Can't call method "disconnect" on an undefined value at
    > /home/virtual/site7/fst/var/www/cgi-bin/affiliates/common.sub line 44.
    >
    > Here is the script I am trying to run:
    I suspect that the script you're trying to run is not called
    "common.sub". Look in that file for line 44.
    > #!/usr/bin/perl
    >
    > use CGI::Carp qw(fatalsToBrowser);
    > #!/usr/local/bin/perl -w
    There is no point in duplicating the #! line.

    > ################## Form Processing Function #########
    This form processing function is utter crap. Not only does it have bugs,
    it does not have a mechanism for preventing DOS attacks by hax0rs who
    upload huge files. It is utterly useless, given that your script also
    uses the fine CGI module, which is not buggy and allows you to limit
    uploads.

    > #require "/var/www/cgi-bin/affiliates/config.cgi"; # you might need
    > the full path to this file
    > require "/home/virtual/site7/fst/var/www/cgi-
    bin/affiliates/config.cgi";
    > # you might need the full path to this file
    > require "/home/virtual/site7/fst/var/www/cgi-
    bin/affiliates/common.sub";
    > # you might need the full path to this file
    According to the error message you posted, the error is in the above
    file.
    > use CGI;
    > use CGI qw(param);
    > use CGI qw/:standard/;
    It's silly to "use" the same module three times. Also, ":standard"
    includes "param". You (or the original author of this script) would have
    known this if you had consulted the CGI module doentation.
    > $q = new CGI;
    ....and importing "param" and ":standard" are superfluous if you use the
    CGI module this way.
    > $ip = $q->remote_host();
    >
    > stuff = $q->param;
    > foreach $stuff (stuff) {${$stuff} = $q->param($stuff);}
    This is a VERY bad way to set variables in your script. First, it does
    no error checking whatsoever. What if the form has a CGI parameter
    called "q"? What if a user maliciously submits a "q" parameter? Here's
    what'll happen. stuff will have "q" among its values. When the loop
    gets to that value, it'll assign "q" to $stuff. Then the body of the
    loop will overwrite your $q variable. The next time through the loop,
    perl will try to call the "param" method on a variable that's no longer
    an object. And your users will see a 500 screen.

    The same goes for any other variable in your script.

    1) Don't use symbolic references until you *really* know what you're
    doing. This will probably not be for years. (that's no reflection on
    you personally; it just takes that long). Using symbolic references is
    "breaking the rules", and you have to know when and why to do so.

    2) There's no real reason to initialize a bunch of global variables with
    every CGI variable. Instead of "$foo", say "$q->param('foo')". Not much
    more overhead, and far safer.
    > &gettheaffiliate;
    In your particular case, this is not really a mistake. But you should
    know that invoking subroutines with a leading & is generally a bad
    practice, and is to be avoided. Break the habit before you develop it.

    > sub gettheaffiliate {
    >
    > $getcookie = $q->cookie($cookiename);
    > if ($getcookie) {}
    > else {
    > &Create_DB_Connection;
    > $SQL="SELECT * FROM hits WHERE Ip='$ip'";
    > &Do_SQL;
    > while ($pointer = $sth->fetchrow_hashref){
    > $getcookie = $pointer->{'Id'};
    > }
    > $sth->finish;
    > $dbh->disconnect;
    > }
    > }
    1) Learn to indent code. The above function is unnecessarily hard to
    read.

    2) This function's reliance (and your program's reliance) on global
    variables is really a bad idea. You have variables being set one place
    and used far, far away. It makes for difficult-to-find bugs. It's
    sloppy.

    3. Instead of

    if ($something) {}
    else {...

    you can do

    if (!$something) {...

    or

    unless ($something) {...
    >
    > I hope someone can help, Thank You in advanced!
    >
    > Justin
    I hope I didn't come down on you too hard. My aim is not to discourage
    you from programming, but rather to encourage you to *think* when you do
    program. Avoid using someone else's code verbatim without grokking what
    it does and why.

    - --
    Eric
    $_ = reverse sort qw p ekca lre Js reh ts
    p, $/.r, map $_.$", qw e p h tona e; print

    -----BEGIN PGP SIGNATURE-----
    Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

    iQA/AwUBPwIRD2PeouIeTNHoEQJk8wCgnH273vl4VF2ib3Zq+Ojgwl NR+EcAmwc3
    XgE+6zBmEwKFVfqTk2Tcgyu4
    =zmgS
    -----END PGP SIGNATURE-----
    Eric J. Roode Guest

  5. #5

    Default Re: "Can't call method "disconnect" on an undefined value..."

    On 1 Jul 2003 12:17:33 -0700,
    Metalbomer <Metalbomer1hotmail.com> wrote:
    > Klaus Johannes Rusch <KlausRuschatmedia.net> wrote in message news:<3F01693B.3EC7CD61atmedia.net>...
    >> Metalbomer wrote:
    >>
    >> > I am new at this and I am trying to figure this out and I don't know
    >> > too much, but I keep getting this error when trying to run my cgi page
    >> > can anyone help, please.
    >> >
    >> > Here is the error:
    >> >
    >> > Can't call method "disconnect" on an undefined value at
    >> > /home/virtual/site7/fst/var/www/cgi-bin/affiliates/common.sub line 44.
    ^^^^^^^^^^
    >> As the error message says, the value is undefined -- without counting lines
    >> in your code, I suspect it's the line $dbh->disconnect, which would hint at
    > That would fine I understood that but the line that errors out is blank. Look here:
    >
    > (LINE 43)$ip = $q->remote_host();
    > (LINE 44)
    > (LINE 45)stuff = $q->param;
    > (LINE 46)foreach $stuff (stuff) {${$stuff} = $q->param($stuff);}
    Is this the file common.sub that you're quoting here? The code you
    posted had a suspiciously commented out line including common.sub,
    while you're actually getting an error about that file.

    Are you sure you're looking at the same sources that you're trying
    to run?

    Martien
    --
    |
    Martien Verbruggen | Never hire a poor lawyer. Never buy from a
    Trading Post Australia | rich salesperson.
    |
    Martien Verbruggen Guest

  6. #6

    Default Re: "Can't call method "disconnect" on an undefined value..."

    ...
    if ($getcookie) {}
    else {
    &Create_DB_Connection;
    $SQL="SELECT * FROM hits WHERE Ip='$ip'";
    ...

    The Create_DB_Connection statement needs as parameter the name of the database like this:
    &Create_DB_Connection(MyDBname);

    if you did before in the mysql-monitor this:
    mysql>create database MyDBname;

    Peter
    Unregistered Guest

Similar Threads

  1. Can't locate object method "newFromJpeg" via package "GD::Image"
    By francescomoi@usa.com in forum PERL Modules
    Replies: 3
    Last Post: December 20th, 11:39 AM
  2. Can't locate object method "blocking" via package "IO::Handle"
    By kemton@kemton.com in forum PERL Modules
    Replies: 1
    Last Post: June 20th, 02:54 PM
  3. Replies: 0
    Last Post: May 24th, 07:35 PM
  4. Can't not locate object method "isadmin" via package "Noc1"
    By Perldiscuss - Perl Newsgroups And Mailing Lists in forum PERL Beginners
    Replies: 1
    Last Post: November 13th, 03:34 PM
  5. Can't call method "uri" on an undefined value
    By chad phillips in forum PERL Miscellaneous
    Replies: 0
    Last Post: September 15th, 04:29 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139