[cgiapp] Loading DBI hashref into HTML::Template Table

adam at spatialsystems.org adam at spatialsystems.org
Thu Sep 25 18:18:55 EDT 2008


I found this method on PerlMonks and can't get it to work.  How do I get
it to work?  I want a simple way to load my DB query into a HTML table. 
Thanks for any advice.



I'm getting this error:

Error executing run mode 'login': DBI selectall_hashref: invalid number
of arguments: got handle + 1, expected handle + between 2 and -1
Usage: $h->selectall_hashref($statement, $keyfield [, \%attr [,
@bind_params ] ]) at /www/perl_modules/VzTools/IBT/WebApp.pm line 120.
 at /www/htdocs/ibt/index.cgi line 9



Here's my relevant template code:

<TMPL_LOOP USERS>
    <tr>
        <td><TMPL_VAR NAME=name></td>
        <td><TMPL_VAR NAME=password></td>
    </tr>
</TMPL_LOOP>
</table>



Here's my WebApp.pm snippet:

sub show_login {

    my $self = shift;

    my $template = $self->load_tmpl( 'login.tmpl', die_on_bad_params =>
0 );


    my $error = "Bad Login Attempt (" . $self->authen->login_attempts .
")" 
        if $self->authen->login_attempts;


    # Fill in some parameters
    $template->param(
        TITLE => 'Login',
        ERROR => $error,
        USERS => $self->dbh->selectall_hashref('select name, password
from users'),
    );

    # Parse the template
    my $html_output = $template->output;
    
    return $html_output;

}





More information about the cgiapp mailing list