in reply to perl, DBI and CGI checkboxes

It might be worth having a look at my take on this sort of thing: HTML::Template nested loops, DBI/MySQL and map. In particular, see rhesa's improvement on my initial attempt.

Replies are listed 'Best First'.
Re^2: perl, DBI and CGI checkboxes
by gogoglou (Beadle) on Mar 25, 2010 at 08:47 UTC
    Thanks everyone for the answer. I used the second reply and it worked. Now my code looks like this:
    #!/usr/bin/perl use DBI; use CGI ':standard'; use strict; use warnings; my $q= CGI->new(); print header, start_html('Advanced Search'); # Connect to the database # See footnote 1 my $dbh = DBI->connect('DBI:mysql:mirnas', 'root', 'pass') or die "Couldn't open database: $DBI::errstr; stopped"; # Getting all the column names and creating checkboxes for them my $table = '07_11_09'; my $sth = $dbh->prepare("SELECT * FROM $table;"); $sth->execute; my @cols = @{$sth->{NAME}}; # or NAME_lc if needed $sth->finish; #printing the checkboxes print checkbox_group(-name=>'fields_to_search', -values=>\@cols # Your array above ); #storing the parameters from the checkboxes my @fields_to_search=param('fields_to_search'); #creating the submit boxes print'<FORM ACTION="http://sirocco/cgi-bin/advanced_search.pl" METHOD="POST">'; print br, '<INPUT TYPE = "SUBMIT"VALUE="Click To Submit">'; print '<INPUT TYPE="RESET"VALUE=Clear>'; print '</FORM>', end_html;
    But when I do that I don't get anything. Also how do I pass the @params to an sql statement Would it be something like my $sth = $dbh->prepare("SELECT * FROM $table WHERE tissue = @fields to search;"); THanks for any possibble answers in advance