in reply to Re: Creating a login page
in thread Creating a login page

So what does this error mean.

Can't call method "header" on an undefined value at Password.pl line 22.

1 #Volunteer.pl - Sign up sheet for Volunteers 2 3 use strict; 4 use DBI; 5 use CGI qw(:standard); 6 7 my ($dbh, $sth, $query); 8 my @player = (); 9 10 11 $dbh = DBI->connect ("DBI:mysql:host=localhost;database=<datab +ase>", 12 "mnlight","<paswword>", 13 {PrintError=> 0, RaiseError=> 1}); 14 15 $sth = $dbh->prepare ("select Player from Roster order by Play +er"); 16 $sth->execute (); 17 18 while (my @row = $sth->fetchrow_array ()) 19 { 20 push @player, $row[0]; 21 22 print $query->header(); 23 print $query->start_html(-title => 'Password');

Edit kudra, 2001-12-22 Replaced br with code

Replies are listed 'Best First'.
Re: Re: Re: Creating a login page
by orkysoft (Friar) on Dec 21, 2001 at 05:06 UTC

    As japh said, you forgot the line:

    my $query = CGI::new;
    which generates a CGI object stored in $query. From then on, you can call methods (header() and such) on the object, while the object knows it's a CGI object (package CGI, and thus knows to find those methods in the CGI module.

    If you forget to initialize the object, you'd be trying to call methods on an undefined value, which doesn't belong to a package, simply because it's undefined.

Re: Re: Re: Creating a login page
by japh (Friar) on Dec 21, 2001 at 04:23 UTC
    perhaps you meant:

    my $cgi = new CGI; print $cgi=>header(); print $cgi->start_html(-title=>'Password');
      I made the change and now I am getting the same error only on start_html instead of header

      Can't call method "start_html" on an undefined value at Password.pl line 26

      #Volunteer.pl - Sign up sheet for Volunteers use strict; use DBI; use CGI qw(:standard); my $query = new CGI; #my $query = CGI::new; my ($dbh, $sth, $query); my @player = (); $dbh = DBI->connect ("DBI:mysql:host=localhost;database=<database>", "mnlight","<password.", {PrintError=> 0, RaiseError=> 1}); $sth = $dbh->prepare ("select Player from Roster order by Player"); $sth->execute (); while (my @row = $sth->fetchrow_array ()) { push @player, $row[0]; print $query=>header(); print $query->start_html(-title=>'Password');. print $query->start_form('POST','/cgi-bin/Password.pl'), print $query->scrolling_list( -name =>'Player', -value =>[@player], -size =>'20'); } print "<p>"; print $query->password_field(-name => 'Password', -size => 8, -override => 1,); print end_form,
        print $query=>header(); should read
        print $query->header();

        you stomped on $query and wound up with the same problem.