I understand to send data to another page, you use:
print start_form(
-action=>'results.cgi');
various form stuff....
print end_form;
I would like to be able to take the selected options from popup_menu's as well as a textbox to return information from a database. So I'm going from a search page to a results page. The search page is displaying information from the database, then whatever the user picks as their selection in the popup_menu gets passed to the results page to query the database.
use DBI;
use CGI::Cookie;
use CGI qw /:standard/;
use warnings;
#checking if cookie is set, if not redirecting to login
my %cookies = CGI::Cookie->fetch;
if (! defined $cookies{'authorized'})
{
print redirect('login.cgi')
}
#connecting to DB
my $dbh = DBI->connect("dbi:SQLite:dbname=/path/to/database.db","","")
+;
# getting artist info
my $sth = $dbh->prepare('select artistid, name from artist');
$sth->execute;
# getting genre info
my $sth2 = $dbh->prepare('select genreid, name from genre');
$sth2->execute;
#printing header
print header,
start_html('Database Search'),
h2('Select items from the dropdown menus to help filter your results.'
+),
br,br,
end_html;
print start_form(-action=>'results.cgi');
end_form; ### THIS CAUSES REDIRECT TO RESULTS WHEN USER HITS SUBMI
+T
############################POPUPS######################
#displaying artist dropdown
my @artistValues;
my %artistLabels;
#this push adds to beginning of values, then it gets set to 'Make a se
+lection' as the default
for the dropdown
push (@artistValues, -1);
print h4('Please select an artist');
$artistLabels{-1} = "Make a selection";
while (my @row = $sth->fetchrow_array)
{
#2 columns in DB, first is ID second is NAME
my $artistId = $row[0];
my $artistName = $row[1];
push(@artistValues,$artistId);
$artistLabels{$artistId} = $artistName;
}
print popup_menu(-name=>'artist',
-values=>\@artistValues,
-labels=>\%artistLabels);
$userArtist = param('artist');
#displaying genre dropdown
my @genreValues;
my %genreLabels;
push (@genreValues, 'Make a selection');
print br,br;
print h4('Please select a genre');
$genreLabels{-1} = "Make a selection";
while (my @row = $sth2->fetchrow_array)
{
my $genreId = $row[0];
my $genreName = $row[1];
push (@genreValues, $genreName);
$genreLabels{$genreId} = $genreId;
}
print popup_menu(-name=>'genre',
-values=>\@genreValues,
-lables=>\%genreLabels);
$userGenre = param('genre');
print br,br;
######################################################################
+##
#displaying trackname textbox
print "Track name: ",textfield('trackname'),br,br
submit('SEARCH'),
$trackName = param('trackname');
while(my @row = $sth->fetchrow_array){
foreach $item (@row){
print "$item ";
}print br;
}
print br,br,br,br,a({href=>'http://www.blablabla.com/logout.cgi'},'Log
+out');
When I go to print the parameters ($userArtist, $userGenre, $trackName), only trackname gets printed and I don't see anything for artist or genre. I am not able to find anything online about this, or maybe I'm just unsure how it works, any help is appreciated.